Creating an quit program macro with a yes/no message

jrod0479

New member
Local time
Today, 11:24
Joined
May 25, 2013
Messages
4
Hello all,

I'm trying to create a button in my main form that runs a macro command to quit Access, but pop up a message box that says "Are you sure you want to quit?", and give a yes/no option. I'm not familiar with the VB code, but I think I can use the macro builder. Can someone help me out? I'm using Access 2007. Thanks.
 
Hello all,

I'm trying to create a button in my main form that runs a macro command to quit Access, but pop up a message box that says "Are you sure you want to quit?", and give a yes/no option. I'm not familiar with the VB code, but I think I can use the macro builder. Can someone help me out? I'm using Access 2007. Thanks.
Create a button on your form which can be used to Quit. You can do this with a macro or with one line of code in the On Click event of the button:
Code:
DoCmd.Quit

Put the following lines of code in the forms UnLoad event:
Code:
    If MsgBox("Are you sure?", vbQuestion + vbYesNo, "Quit Program") = vbNo Then
        Cancel = True
    End If
 
Where would I find the unload event? I went to the bottom of the code window and didn't find it.
 
Open the form in "Design" view.
Open the forms Property sheet.
Click the "Events" tab.
Find On Unload in the list and click in the column.
You should then see what looks like the dropdown arrow of a combo box. Click it and then select [Event Procedure].
In the right margin you should also see a button with three dots ...
Click these dots to open the forms code module. It should open showing:
Code:
Private Sub Form_Unload(Cancel As Integer)

End Sub
Put the code from my earlier post between these two lines, like this:
Code:
Private Sub Form_Unload(Cancel As Integer)
    If MsgBox("Are you sure?", vbQuestion + vbYesNo, "Quit Program") = vbNo Then
        Cancel = True
    End If
End Sub
 
You must create the event via the Form Editor if the event does not currently exist.

Open the Form in Design View
Have the Property Sheet open
Event tab, while the "Section Type" pick list is set to Form
Locate the "On Unload" event, when you are successfully selected on that event, two buttons will show up at the right of that row...
Click the down arrow and select "[Event Procedure]"
Then click the [...] button to be brought to the VBA editor and that new event will have been created for you

Nothing to it! :cool:
 
I havea form with a quit button. I added the code to the Unload event. No matter if you press the quit button or Access close button, the msg box appears but whtheryou press no or yes, the Access closes.
 

Users who are viewing this thread

Back
Top Bottom