Button with Message Pop Up

lklp

Registered User.
Local time
Today, 05:18
Joined
Aug 18, 2006
Messages
17
This is probably very simple, but how and where do I add codes to the button where a confirmation message pops up? Like, "Are you sure you want to save?" or "Are you sure you want to exit?"

For Example: Save and Close button

Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click

DoCmd.Close

Exit_cmdClose_Click:
Exit Sub

Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click

End Sub


Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_cmdSave_Click:
Exit Sub

Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click

End Sub


Thanks in advance!
 
In Design view, right-click the button, select the On Click event, press the elipsis .. select code builder and then drop the code in. After you have coded one event, you can get to the Visual Baisc Editor by selecting the code icon in the top toolbar. This is the squarer with the coloured sides.
 
Hi Ted,

The codes are already in the On Click [Event Procedure], I wasn't sure how to add a message to the current codes when a user press the button the message pops up.

Sorry for the confusion. Thanks!
 
Use the msgBox function Before the final event

e.g.

Dim iResponse as Integer

iResponse = MsgBox("Ask the Question?", vbOKCancel, "Message Box Title")
If iResponse <> 1 Then ' 1 is OK 2 or X is Cancel
' Do something like Cancel = True or Exit Sub
else
docmd.close
end if
 
Last edited:
Code:
If Msgbox("Do you want to close?",vbyesNo + vbquestion, "Close?") = vbyes then
Docmd.close

End If
 
Hi Ted,

Thanks, it works like a charm. Is there anyway, the user can select Yes or No from the Message Box? Right now, it only has an OK button. Thanks again!

Private Sub cmdSave_Click()
On Error GoTo Err_cmdSave_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MsgBox "Are you sure you want to save?", vbInformation, "Confirmation"
Exit_cmdSave_Click:
Exit Sub

Err_cmdSave_Click:
MsgBox Err.Description
Resume Exit_cmdSave_Click

End Sub
 

Users who are viewing this thread

Back
Top Bottom