View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default load/unload userform

Fred,

You can trap that event, and cancel it

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then
Cancel = True
End If
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Nigel" wrote in message
...
Not sure if it will help but I use the following test to control the
switching between two overlayed forms......
If the form is not initialized this will return false as well.

UserForm1.Visible = True

--
Cheers
Nigel



"Fred" wrote in message
...
I have created a userform with an Initialize event that loads the

userform
from a database.
To use the form I run

Load myForm
myForm.Show
Unload myForm

The form has an OK Button and a Cancel button which both hide the form

and
then the next line of code unloads (terminates) the form.

It all works OK except when the user closes the form by clicking the

form's
close button (top right cross).
When this happens the form actually terminates so when the Unload myForm
code runs, because myForm has been terminated it is first re-initialized
before it is then terminated.
Although there are no errors and it still works OK it is annoying as the
initialize event downloads quite e bit of data and so takes quite a

while.

Is there any way I can find out if myForm has been terminated before I

run
the Unload command.

Thanks,
Fred