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!

Disable the "X" button using VB with Word Temp.

Status
Not open for further replies.

blackte

Programmer
Jul 24, 2001
80
US
I have a Word Temp, that has a dialog box that contains the "X" (button upper right hand corner), for closing the dialog box. I would like to disable or remove it from the box, can anyone give me any help with where to look or how to go about doing this. They are using this button to close out when they should be using one of the other 5 buttons to finish the task at hand.

Any help with this is greatly appreciated. Thanks again

Thanks Travis.
 
Hi Travis,

You need to put code in the UserForm_QueryClose Event handler. This is passed a parameter called "CloseMode" which gives indication of how the request to close the form was made. If the [X] was pressed it will have a value of vbFormControlMenu (=0). You can take whatever action you like but simply to stop the event happening all you need to do is set Cancel = True. See code example below.

Code:
Private Sub UserForm_QueryClose(Cancel as Integer, CloseMode as Integer)
    If CloseMode = vbFormControlMenu Then Cancel = True
End Sub

Enjoy,
Tony
 
Tony, your example looks to diable the "X", can it be removed completely or not? Thanks again for your help, it is greatly appreciated.



Thanks Travis.
 
Not as far as I know. All you can do is disable it.

It's worth noting that it is possible to close a window in other ways: by pressing <Alt><F4>, or by clicking in the top left and selecting Close. These mechanisms are also caught by checking for CloseMode = vbFormControlMenu. If you simply removed the [X] they would still be available to the User.

Enjoy,
Tony
 
Tony, thanks I will give it a try. I appreciate your help.

Thanks Travis.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top