Userform QueryClose Problems

andyh69uk

New Member
Joined
Nov 23, 2005
Messages
31
Hi,

I have been trying to get several userforms to load, unload, hide etc and generally behave properly. This is isn't the actual code however this is the sort of problem I am having. I am trying to load and unload forms from other forms, however when I go back to a form that has been unloaded it doesn't work, by that i mean it shows the form but nothing on it works. A really basic example of my problem, two userforms both with buttons on, button1 on userform1 calls userform2 (unload, load, show). Button2 on userform2 does the same but userform2 also uses queryclose to set a boolean variable and then runs code on terminate if that boolean is true. The code it runs is exactly the same as if the button has been pressed however when userform2 is reloaded from userform1 it doesn't work. This is the code from userform2:-

Code:
Private trueOrNot As Boolean
Private Sub CommandButton1_Click()
Unload Me
Load UserForm1
UserForm1.Show
End Sub

Private Sub UserForm_QueryClose(cancel As Integer, closemode As Integer)
    If closemode = vbFormControlMenu Then trueOrNot = True
End Sub


Private Sub UserForm_Terminate()
If trueOrNot = True Then
    Unload Me
    Load UserForm1
    UserForm1.Show
End If
End Sub

Userform1 justs has code for the cmdbutton to open userform2.

Any advice would be much appreciated

Thanks

Andy
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
I didn't cross-post, the link you provided doesn't answer the question, in the link example he is trying to carry out the commands as part of the QueryClose. I am unloading and loading upon terminate. I have tried running this code with msgbox's doing a UserForms.Count and the forms appear to be loading and unloading correctly. However the button on the form and the close 'x' do nothing the second time it is loaded.

Any help would be most appreciated
 
Upvote 0
If anyone has got a minute could they try running this code and posting back if you are getting the same results this is driving me nut

Thanks

Andy
 
Upvote 0

Forum statistics

Threads
1,226,223
Messages
6,189,710
Members
453,566
Latest member
ariestattle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top