userform on top of another userform -> runtime error 402

webster188

New Member
Joined
Oct 20, 2010
Messages
31
Hello,

Trying to find a solution for following problem:

I have an application using two userforms
Following sequence is used:

1. Open Userform1 (with uf.show)
2. click on a commandbutton in userform1 opens a second userform on top of userform1.
3. Close userform2 with commandbutton on userform2 (userform2.hide)
(I did not want the user to close the UF via the "X" )

Runtime error 402 : Must close or hide topmost modal form first


So, I changed my code so when the user clicks the commandbutton in userform2

userform1.hide (which is the topmost)
userform2.hide

But again I get the same error.

What am I doing wrong here??

Regards,

Dimitri
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
The only way I could replicate your problem was if I tried to close the first form with the button on the second form. Have you definitely got your form names correctly entered?

Edit

For the second button you could try Me.Hide
 
Last edited:
Upvote 0
Hi Gsbelbin,

Yes, I tried and it works. :)

What is the secret here? Me.hide is working, Userformname.Hide does not


Regards,

Dimitri
 
Upvote 0
go into the properties of the first userform and change the show modal property to FALSE

A modal window locks the application from doing anything else until it is closed, hence the requirement to close the first form before closing the second form.
 
Upvote 0
It should work either way and does so when I try it. Like I said, the only way I could get it to fail was if I tried closing the first form using the second form's button.
 
Upvote 0
obiron, what you've suggested will work but it's not what I believe Dimitri is trying to do. He's having problems closing the second form.
 
Last edited:
Upvote 0
Hi!
Try this...


'Capture the [X] button click
If CloseMode = vbFormControlMenu Then

'Stop the default unload close
Cancel = True

'Force the Hide close
Me.Hide

End If

End Sub[/CODE]
 
Upvote 0

Forum statistics

Threads
1,214,851
Messages
6,121,931
Members
449,056
Latest member
denissimo

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