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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Userform clos problem 3

Status
Not open for further replies.

ribhead

Technical User
Jun 2, 2003
384
US
I am using a lot of Userforms and I don't want the users to close the form in the upper right corner. What can be done to prevent this? Maybe this is a simple fix but I know very little about VBA or anything else for that matter. Any help would be appreciated.
 
Try something like this:
[blue]
Code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  If CloseMode = vbFormControlMenu Then
    MsgBox "You can only close when I say so!"
    Cancel = True
  End If
End Sub
[/color]

 
I believe I type in the info you have and it didn't work. Should I be typing in my form name right after VB? Example VbUserform2? I did this and nothing happens. Any thoughts?
 
I'm guessing you tried to put that code in a code module. It needs to go in the form's code page. Let the VBA editor do the work for you:

1. Double-click on a blank spot the form. This should open the VBA editor and display the code page for your form. If you do this on a new workbook and an empty form, the title bar should show "Book1 - UserForm1 (Code)" If you do this on your form, you should see your workbook and form names in the title bar.

2. In the left-hand combo box, select "UserForm" This should put the code stub for a Click event in the window:
[blue]
Code:
Private Sub UserForm_Click()

End Sub
[/color]

3. Delete those lines. You don't need them.

4. In the right-hand combo box, select "QueryClose" This should put the code stub for a QueryClose event in the window:
[blue]
Code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

End Sub
[/color]

5. Fill in the code between the "Private Sub" and "End Sub" lines with the code I posted above.



 
Sorry about that but I thought I reposted. I checked this out and I missed a letter in UserForm. This did work. Works Great actually.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top