Storing the output from a Msgbox

  • Thread starter Thread starter John Ortt
  • Start date Start date
J

John Ortt

I have a macro which deletes all the data in the database when an
Administrator desires to do so.

It would not be a disaster if it was run by accident but I would like a
"second chance button" incase the user presses it by accident.

I want to use a message box with the message "Are you sure you want to do
this?" and a Yes/No option result.

If the result is a Yes then it goes ahead otherwise it aborts.

My code to do this was as follows but it does not seem to work:

Function SecondChanceCode()
MsgBox "Are you Sure?", vbYesNo
If VbMsgBoxResult("Yes") Then
MsgBox "Good"
'Code to run delete macro to be inserted here and comment removed
Else: MsgBox "Too Bad"
'Comment to be removed
End If
End Function

Any advice would be greatly appreciated.

Thanks,

John
 
Just a slightly different syntax that I use (make sure to get the entire
If...Then statement together on one line):

If MsgBox("You are about to clear all data from this database. Are you sure
you want to do this?",_vbExclamation + vbYesNo, "Clear all data?") = vbYes
Then
DoCmd.SetWarnings False
DoCmd.RunQuery "<Enter your delete query name here>"
DoCmd.SetWarnings True
End If

The vbExclamation returns the yellow triangle & exclamation, which should
catch the user's attention. The DoCmd.SetWarnings False/True just bypasses
the query-related Yes/No dialogues that would otherwise appear.
 
Back
Top