[RESOLVED] How to disable userform close button
When I create userforms within Word 2003, the default close button (red cross) appears on the top right corner of each form.
My forms are set up so that the user has to:
Fill in the form and click cmdOK to complete the document.
Or
Press cmdCancel, in which case Word exits and no changes are applied.
Does anybody know a means to disable this button or, if it can not be disabled easily, execute my cmdCancel code when it is pressed?
Thanks in advance :)
Re: How to disable userform close button
Add this code to your form.
VB Code:
Private Sub UserForm_Terminate()
Call cmdCancel_Click
End Sub
Re: How to disable userform close button
I prefer to use the _QueryClose event of the form.
Using _Terminate means that the cmdCancel_Click proedure is called even when you close the form programatically, unless you trap for that.
VB Code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
cmdCancel_Click
Cancel = True
End If
End Sub
Re: How to disable userform close button
Thanks for the response mikeyc1204 and DKenny.
I tried both methods, but had a couple of problems. As you pointed out DKenny, using _Terminate caused an error when the form was closed programatically, i.e. using cmdCancel, and I don't know how to "trap" for that (excuse the ignorance :) ).
The _QueryClose event sort of worked - the document closed and no changes were saved, although the form itself remained open and I had to ctrl+alt+del to close it. To resolve this I removed Cancel = True and it works perfectly.
Thanks again for the help.
Re: [RESOLVED] How to disable userform close button
Perhaps actually disabling the 'x' would work better for you. :)
http://www.vbforums.com/showthread.php?t=363931
Re: [RESOLVED] How to disable userform close button