load/unload userform

F

Fred

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
 
N

Nigel

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
 
B

Bob Phillips

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)
 
F

Fred

Thanks Bob,
that works fine.


Bob Phillips said:
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top