Preventing Form Close (1 Viewer)

ramhanuman

Registered User.
Local time
Yesterday, 21:26
Joined
May 1, 2012
Messages
13
If the user clicks the close button on the top right of the form window, or the big X, I made it so that it pops up a window asking the user if they really want to exit or not. If the user clicks no, how do I prevent the window from closing? Thanks
 

bob fitz

AWF VIP
Local time
Today, 05:26
Joined
May 23, 2011
Messages
4,726
Use the form's Unload event to ask the user. If the user doesn't want to close then use this line of code to cancel the unload event:
Cancel = True
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:26
Joined
Feb 19, 2002
Messages
43,392
There is no way to trap a click event on the Access window. For a form, you would use the UnLoad event.

If Msgbox("Do you really want to close this form?"),vbYesNo = vbNo Then
Cancel = True
End If
 

bob fitz

AWF VIP
Local time
Today, 05:26
Joined
May 23, 2011
Messages
4,726
Pat

I think you'll find that using the code you have given, it will stop the form from closing and there by stop the app from closing as well.

I think the code you meant to post is:
Code:
If MsgBox("Do you really want to close this form?", vbYesNo[COLOR=red][B])[/B][/COLOR] = vbNo Then
Cancel = True
End If
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 00:26
Joined
Feb 19, 2002
Messages
43,392
I just washed my hands and can't do a thing with them:) Thanks.
 

Users who are viewing this thread

Top Bottom