Confirmation Dialog

  • Thread starter Thread starter arnold
  • Start date Start date
A

arnold

I have a macro in Access that I want to run when someone clicks a
command button. The code is as follows:

Private Sub Terminate_Click()
On Error GoTo Err_Terminate_Click

Dim stDocName As String

stDocName = "Terminate"
DoCmd.RunMacro stDocName

Exit_Terminate_Click:
Exit Sub

Err_Terminate_Click:
MsgBox Err.Description
Resume Exit_Terminate_Click

End Sub

I would like to add a confirmation dialog box to confirm that the user
wants to terminate the record. How do I add that to the code to make
it work? If they click "no" I want it to return to the record. If
they click "yes" I want to it run the macro. Any help would be
appreciated!
 
You could try something like this:

If MsgBox("Terminate?", vbOkCancel) = vbOk Then
DoCmd.RunMacro stDocName
End If

But there are numerous other issues that could affect the number of
confirmation dialogs the user would have to deal with here.

If this button is to delete the record, you could try something like this:

If Me.Dirty Then Me.Undo
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
 

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

Similar Threads

Report printing 1
Report printing 15
Run Macro command 5
Report Missing Data 2
search command 2
Code Only works first time! 2
Jet Engine Error Message 2
Open a form and close one 1

Back
Top