How preventing a close-button in dialog fields? 
Author Message
 How preventing a close-button in dialog fields?

Hi!

How can I prevent a dialog field appearing with a close-
button in the upper right corner? I want the user to click
either the OK-Button or the Cancel-Button which starts
according functions.

Thanks for helping
Tobi



Mon, 13 Sep 2004 02:22:51 GMT  
 How preventing a close-button in dialog fields?
Tobi

you can test the CloseMode variable.  If it is set to 0, the user has
clicked the "x".  If it is set to 1 then the form has been unloaded.

Try the following as an example; create a new form and add a single button.
Add the following code to the form:

Private Sub CommandButton1_Click()
Unload Me
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
MsgBox CloseMode
If CloseMode = 0 Then Cancel = True
End Sub

Now load the form; clicking the "x" displays the Message Box and then
cancels the close.

Regards

Trevor


Quote:
> Hi!

> How can I prevent a dialog field appearing with a close-
> button in the upper right corner? I want the user to click
> either the OK-Button or the Cancel-Button which starts
> according functions.

> Thanks for helping
> Tobi



Mon, 13 Sep 2004 02:55:10 GMT  
 How preventing a close-button in dialog fields?
Tobi, what you want can be done (and I"m certain someone will post that
solution shortly).  However, it is easier to have your OK and Cancel buttons
set a global variable to indicate which has been clicked.  For example, if
you create a global variable call buttonNum

Public buttonNum  'at top of module

You would initialize it to zero before displaying your form

buttonNum = 0
'code to show userform
'user form buttons set to 1 if Cancel and 2 if OK

Then when the execution returns to the code,  you check the value for the
action to take.  If set to 0, just loop back and redisplay the form

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel


Quote:
> Hi!

> How can I prevent a dialog field appearing with a close-
> button in the upper right corner? I want the user to click
> either the OK-Button or the Cancel-Button which starts
> according functions.

> Thanks for helping
> Tobi



Mon, 13 Sep 2004 02:46:01 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Prevent user from closing form using caption close button

2. Preventing save dialog box on close

3. Preventing save dialog box on close

4. Close command button allows form to be closed when required fields are left blank

5. How can I prevent users from closing a form with the caption button (x)

6. VBA Excel 2000 - How to prevent the Close button on a user form

7. Prevent user form closing Access with the X button

8. Removing system menu and close button to prevent exit from Word

9. Disable Access Close Button not Form Close Button?

10. close button on custom dialog sheet


 
Powered by phpBB® Forum Software © phpBB Group