View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default 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