Msg Box before Macro Start

daniela

New member
Local time
Today, 17:49
Joined
Dec 14, 2005
Messages
9
Hello,

I have a button that runs a macro to delete records in 12 tables. I want to create a message box before that macro runs warning that you are deleting records in 12 tables and are your sure you want to run the macro.

I need a message box with an ok and cancel button. Where do I put the msgbox funtion in this code?

Thanks !!

This is my code:

Private Sub cmdRunDeleteMacro_Click()
On Error GoTo Err_cmdRunDeleteMacro_Click

Dim stDocName As String

stDocName = "mcrSemesterStartRecordDELETE"
DoCmd.RunMacro stDocName

Exit_cmdRunDeleteMacro_Click:
Exit Sub

Err_cmdRunDeleteMacro_Click:
MsgBox Err.Description
Resume Exit_cmdRunDeleteMacro_Click

End Sub
 
Try putting the following code in front of your stDocName = "mcrSemesterStartRecordDELETE" DoCmd.RunMacro stDocName

If MsgBox("This is where your message will show", vbYesNo + vbQuestion, "Warning") = vbNo Then
Exit Sub
End If

Let me know if it works for you.

Alastair
 
Code:
Private Sub cmdRunDeleteMacro_Click()
On Error GoTo Err_cmdRunDeleteMacro_Click

Dim stDocName As String
Dim sMsg As String
sMsg = "You are deleting records in 12 tables and are your sure you want to run the macro?"

'Should look like this
If MsgBox(sMsg, vbOKCancel) = vbOK Then
'If they click OK then run the macro
    stDocName = "mcrSemesterStartRecordDELETE"
    DoCmd.RunMacro stDocName
End If

Exit_cmdRunDeleteMacro_Click:
Exit Sub

Err_cmdRunDeleteMacro_Click:
MsgBox Err.Description
Resume Exit_cmdRunDeleteMacro_Click

End Sub
 
Thanks, Alastair, from another user who found your short, sweet and directly to the point post from the search feature:

If MsgBox("This is where your message will show", vbYesNo + vbQuestion, "Warning") = vbNo Then
Exit Sub
End If


It worked for me, also!
 

Users who are viewing this thread

Back
Top Bottom