Close Button

  • Thread starter tobesurveyor via AccessMonster.com
  • Start date
T

tobesurveyor via AccessMonster.com

Good Evening,

Instead of forcing a user to use a button to close out of the database I want
to allow the user to click the red - x in the right hand corner of Access
Window. To make sure the user wants to close the entire application, I have
a hidden form with the On_Close Event to be a message box prompting the user
to say "yes" if they want to exit or No to stay in the program. Even if they
click no, access still closes. Right now my Code is:

msg = "Are you Sure you want to quit the Survey Management Suites?"
prompt = vbYesNo + vbQuestion
TITLE = "Exiting Survey Management Suites..."

Response = MsgBox(msg, prompt, TITLE)
If Response = vbYes Then
If IsLoaded("frmLoginHidden") Then
DoCmd.Close acForm, "frmLoginHidden", acSaveNo
End If
Else
Exit Sub
End If

Am I missing something, what should my line of code be to cancel Access from
Closing?

Any help in this would be greatly appreciated,
Thanks,
Chris
 
F

fredg

Good Evening,

Instead of forcing a user to use a button to close out of the database I want
to allow the user to click the red - x in the right hand corner of Access
Window. To make sure the user wants to close the entire application, I have
a hidden form with the On_Close Event to be a message box prompting the user
to say "yes" if they want to exit or No to stay in the program. Even if they
click no, access still closes. Right now my Code is:

msg = "Are you Sure you want to quit the Survey Management Suites?"
prompt = vbYesNo + vbQuestion
TITLE = "Exiting Survey Management Suites..."

Response = MsgBox(msg, prompt, TITLE)
If Response = vbYes Then
If IsLoaded("frmLoginHidden") Then
DoCmd.Close acForm, "frmLoginHidden", acSaveNo
End If
Else
Exit Sub
End If

Am I missing something, what should my line of code be to cancel Access from
Closing?

Any help in this would be greatly appreciated,
Thanks,
Chris

Wrong event.
Code the Form's Unload event:

If MsgBox("Your message here", vbYesNo + vbQuestion,"YourTitle Here")
= vbYes Then
Else
Cancel = True
End If

If you wish to default the Yes/No selection to No then use
vbYesNo + vbQuestion + vbDefaultButton2
otherwise Yes is the default.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top