Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forms won't unload

Status
Not open for further replies.

007MCSE

IS-IT--Management
Jan 3, 2003
51
0
0
US
Ok

I have a main form and 2 subforms

The 2 subforms both have two command buttons "save" & "Quit"
Under Save_Click and Quit_Click the unload commands
Unload LedColors Unload Speedsetup
Unload PPortLc1 (main form) Unload PPortLc1 (main form)

It works the first time. then the second time I get the following errors:-

Runtime error 402
Must Close or hide topmost model form first.

It dosent mater which order I put the Unloads in, I get the same error.

Also on the main form, i had to do the same unload the form, because every time you did something on the main form, it would open another copy of the form.

The old form does unload 3 or 4 times then after that it dosen't unload and I end up having loads of forms visable on the screen
 
If I'm reading this right you should only be able to open one of the subforms (vbModal) at a time from the main form.

The problem then is that you are referencing the other subform when it should not exist and therefore are creating a new instance of it.

Only unload the forms that would actually exist when the button is pushed...

subform1

Unload subform1
set subform1 = nothing

Unload main
set main = nothing

subform2

unload subform2
set subform2 = nothing

unload main
set main = nothing

k2w
 
You can sometimes get this too when you Dim oForm as New myForm. This creates an auto-instancing variable, which can cause this problem. Instead, instantiate your object variables in two steps:
Code:
Dim oForm As MyForm
Set oForm = New MyForm
:
:
Set oForm = Nothing
Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top