Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to avoid re-initialisation when Unloading form
Hi,
It's got to be a newbie question: I have, for a change, stuff in MyForm_Initialize that can yield an error. I trap it with On Error GoTo, where Msg explains it to user. Now, if there's no other statements past Msg, I get to see troubled form anyway. If I put Unload Me after Msg then this triggers Initialize and there we go again with error, trapping of it, Msg etc. Looping, mind you. How do you avoid this situation elegantly? TIA Paul |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to avoid re-initialisation when Unloading form
Then name of the initialize event should be
Private Sub Userform_Initialize() so I am not sure what you get wtih MyForm_Initialize The initialize event shouldn't be fired by an unload command unless the the form is not loaded. Are you using Unload Me -- Regards, Tom Ogilvy "count" wrote in message ... Hi, It's got to be a newbie question: I have, for a change, stuff in MyForm_Initialize that can yield an error. I trap it with On Error GoTo, where Msg explains it to user. Now, if there's no other statements past Msg, I get to see troubled form anyway. If I put Unload Me after Msg then this triggers Initialize and there we go again with error, trapping of it, Msg etc. Looping, mind you. How do you avoid this situation elegantly? TIA Paul |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to avoid re-initialisation when Unloading form
Paul,
I didn't quite get what you did, but I got an error after the Unload. I got around it like so Dim fShutDown As Boolean Private Sub UserForm_Activate() If fShutDown Then Unload Me End If End Sub Private Sub UserForm_Initialize() Dim a As Long On Error GoTo uf: a = "abc" Exit Sub uf: MsgBox "hello" Err.Clear fShutDown = True End Sub -- HTH RP (remove nothere from the email address if mailing direct) "count" wrote in message ... Hi, It's got to be a newbie question: I have, for a change, stuff in MyForm_Initialize that can yield an error. I trap it with On Error GoTo, where Msg explains it to user. Now, if there's no other statements past Msg, I get to see troubled form anyway. If I put Unload Me after Msg then this triggers Initialize and there we go again with error, trapping of it, Msg etc. Looping, mind you. How do you avoid this situation elegantly? TIA Paul |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to avoid re-initialisation when Unloading form
Użytkownik "Tom Ogilvy" napisał w wiadomości ... Then name of the initialize event should be Private Sub Userform_Initialize() so I am not sure what you get wtih MyForm_Initialize Sure the name is indeed Userform_Initialize() .... just my deconcentration - pls forgive :) Picture is worth 1000 words,,,, '-------------- code below lives in sheet "Menu" Private Sub Label7_Click() 'add doc using Ahold setup WZType = "WZAhold" 'that's just a parm passed AddWZTyped.Show End Sub '--------------- Private Sub UserForm_Initialize() ' this code within AddWZTyped form .... On Error GoTo NoPrice ..... With AddWZTyped.Controls.Item("Opis" & Trim(Str(n))) .Caption = Sheets("Cennik").Cells(Sheets("Cennik").Range("A:A ").Find(What:=.... Find might fail End With ..... more statements SPOT Exit Sub NoPrice: MsgBox ("Small prob" & vbCrLf & "No entry for item " & rng(n, 1) & vbCrLf & "Pls check setup [...]") Unload Me End Sub '----------------------------------------------------------- When Unload Me is omitted, the form still shows crippled by no execution of "more statements SPOT" With Unload Me it aborts at line AddWZTyped.Show "Object variable not..." When Debug and F8-ting, it goes into _Initialize and aborts again when .Find unsuccessful Should I try to Load form before .Show? Thanks Tom in advance - I haven't had situation before where error can strike at _Initialize. Paul Regards, Tom Ogilvy "count" wrote in message ... Hi, It's got to be a newbie question: I have, for a change, stuff in MyForm_Initialize that can yield an error. I trap it with On Error GoTo, where Msg explains it to user. Now, if there's no other statements past Msg, I get to see troubled form anyway. If I put Unload Me after Msg then this triggers Initialize and there we go again with error, trapping of it, Msg etc. Looping, mind you. How do you avoid this situation elegantly? TIA Paul |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to avoid re-initialisation when Unloading form
The easiest approach would be to do your checking in the code that
shows/loads the userform. If Find fails, don't issue the command to show the form (just diplay your warning message). -- Regards, Tom Ogilvy "count" wrote in message ... Użytkownik "Tom Ogilvy" napisał w wiadomości ... Then name of the initialize event should be Private Sub Userform_Initialize() so I am not sure what you get wtih MyForm_Initialize Sure the name is indeed Userform_Initialize() .... just my deconcentration - pls forgive :) Picture is worth 1000 words,,,, '-------------- code below lives in sheet "Menu" Private Sub Label7_Click() 'add doc using Ahold setup WZType = "WZAhold" 'that's just a parm passed AddWZTyped.Show End Sub '--------------- Private Sub UserForm_Initialize() ' this code within AddWZTyped form ... On Error GoTo NoPrice .... With AddWZTyped.Controls.Item("Opis" & Trim(Str(n))) .Caption = Sheets("Cennik").Cells(Sheets("Cennik").Range("A:A ").Find(What:=.... Find might fail End With .... more statements SPOT Exit Sub NoPrice: MsgBox ("Small prob" & vbCrLf & "No entry for item " & rng(n, 1) & vbCrLf & "Pls check setup [...]") Unload Me End Sub '----------------------------------------------------------- When Unload Me is omitted, the form still shows crippled by no execution of "more statements SPOT" With Unload Me it aborts at line AddWZTyped.Show "Object variable not..." When Debug and F8-ting, it goes into _Initialize and aborts again when ..Find unsuccessful Should I try to Load form before .Show? Thanks Tom in advance - I haven't had situation before where error can strike at _Initialize. Paul Regards, Tom Ogilvy "count" wrote in message ... Hi, It's got to be a newbie question: I have, for a change, stuff in MyForm_Initialize that can yield an error. I trap it with On Error GoTo, where Msg explains it to user. Now, if there's no other statements past Msg, I get to see troubled form anyway. If I put Unload Me after Msg then this triggers Initialize and there we go again with error, trapping of it, Msg etc. Looping, mind you. How do you avoid this situation elegantly? TIA Paul |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Not Unloading a UserForm | Excel Programming | |||
Unloading User Forms? | Excel Programming | |||
Unloading A Form | Excel Programming | |||
Unloading an Add-In | Excel Programming | |||
How can I avoid form destruction?? | Excel Programming |