Message box before close database

Birkofas

New member
Local time
Today, 17:03
Joined
Apr 29, 2008
Messages
8
Hi Everyone

I need the message box appear then user click button (X) to close database. Have you got any suggestions how to do this?

Thanks in advance
 
Private Sub Quit_Click()
Dim intResponse As Integer
intResponse = Msgbox("Are you sure you want to quit?",vbYesNoCancel)
Select Case intResponse
Case vbYes
'Docmd.Quit
Case vbNo
'Exit anyway
Case vbCancel
'Cancel
End Select
End Sub
 
Private Sub Quit_Click()
Dim intResponse As Integer
intResponse = Msgbox("Are you sure you want to quit?",vbYesNoCancel)
Select Case intResponse
Case vbYes
'Docmd.Quit
Case vbNo
'Exit anyway
Case vbCancel
'Cancel
End Select
End Sub

This will not stop the database from exiting if the X is clicked.

What I will typically do will open a hidden form and in it's UNLOAD event I put
Code:
If MsgBox("Are you sure you want to close the program?",vbQuestion,"Close Confirmation") = vbNo Then
    Cancel = True
End If
 
boblarson could you explain little bit more how to hide form.
Is it any chance to put buttons like ok and cancel?
 
Okay,

1. Create a form - nothing on it just a form.
2. Save it
3. While in the form is open in Design view, go to the Events tab on the properties dialog and in the Unload event, select the drop down that says [EventProcedure].
4. Click on the ellipsis (...) that appears next to that
5. That will take you to the code window
6. Place this code in the Unload event:
Code:
Dim varResp As Variant

    varResp = MsgBox("Are you sure you want to close the program?", vbYesNo, "Close Confirmation")
    Select Case varResp
        Case vbYes
           DoCmd.Quit
        Case vbNo
           Cancel = True
           Exit Sub
    End Select
    Exit Sub

To set the form as hidden, you would just right click on it in the Database Window and select the HIDDEN checkbox.

To open the form when your program opens, put this code in the On Open event of your main form:

DoCmd.OpenForm "HiddenFormNameHere", acNormal, , , , acHidden
 
Last edited:
Thanks a lot for your advise. I changed litle bit the code and it works!!!



Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Are you sure you want to close the program?", vbYesNo) = vbNo Then
Cancel = True
Else
Exit Sub
End If
End Sub
:D
 

Users who are viewing this thread

Back
Top Bottom