MsgBox to do three things...Need a little help...

A

AccessNubee

**Pulling hair out**
I have the following code for an "Exit" button to do three things:
1. If yes is clicked, then save everything and close the application
2. If No is clicked, then prompt to just close the form, if yes, then close
the form if no then leave it open and do nothing
3. If Cancel is clicked, then do nothing and show "Action Cancelled"

I intend to use the same code for all the Exit buttons on my forms so this
is in the Common module
The Yes click works - it will close the application. Great!
I can't figure out why the rest doesn't work. What am I missing?

---------------------------------------------------------------
Public Function cmdExitDatabase()
On Error GoTo Err_cmdExitDatabase

Dim Reply As Variant

Reply = MsgBox("Are you SURE you want to EXIT the database?" & vbNewLine &
"Click No to close this form" & vbNewLine & "Click Yes to EXIT the
Database", vbYesNoCancel, "Exit Confirmation")
Select Case Reply

'If Yes is clicked, then save all and close the application
Case vbYes:
DoCmd.Quit acSaveAllRecords
MsgBox "Have a Great Day!"
Case vbCancel:
'If Cancel is clicked, then Cancel the Action!
MsgBox "Close Cancelled"
'If No is clicked, Just close the form.
Case vbNo:
If MsgBox("Do you want to close the FORM", vbYesNo, "Close
Form?") = vbOK Then
'Close the form
DoCmd.Close
End If
End Select

Exit_cmdExitDatabase:
Exit Function
Err_cmdExitDatabase:
MsgBox Err.Description
Resume Exit_cmdExitDatabase
End Function
-----------------------------------------------------------------
 
A

AccessNubee

OK... fixed my own problem.. In the first post, I had "=vbOK Then" it
should have been "=vbYes Then"
and I added an "Else" to the end to do nothing. This works for me now .

---------------------------------------------------------------------------------------
Dim Reply As Variant

Reply = MsgBox("Are you SURE you want to EXIT the database?" & vbNewLine &
"Click No to close this form" & vbNewLine & "Click Yes to EXIT the
Database", vbYesNoCancel, "Exit Confirmation")
Select Case Reply

'If Yes, then close the application
Case vbYes:
DoCmd.Quit acSaveAllRecords
MsgBox "Good Bye!"

'Cancel the Action!
Case vbCancel:
MsgBox "Close Cancelled"

'No, Just close the form.
Case vbNo:
If MsgBox("Do you want to close the FORM", vbYesNo, "Close
Form?") = vbYes Then
'Close the form
DoCmd.Close
Else
'do nothing
End If

End Select
 

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