MsgBox Function

  • Thread starter Thread starter Brian Cheresnowsky
  • Start date Start date
B

Brian Cheresnowsky

I am having trouble writing code for a message box. This
is the scenario:

I have a macro that updates data from several sources
overnight. In the event that the process doesn't run, I
want to add a button on a form to run the process. I
want a message box to pop that will read: "Please verify
that process did not run before continuing. Press OK if
you want to rerun the process, or click Cancel to
abort." If the user clicks ok, then the macro would
run. I think I am having trouble understanding the
vbCancel string.

Can anyone help?

Thanks!

Brian
 
Hi Brian,

In this situation I'd probably use something like this:

Const MSG_1 = "Please verify that process did not " _
& "run before continuing. Press OK if you want to " _
& "rerun the process, or click Cancel to abort."
Const MSG_TITLE = "Verify Process"

....

If MsgBox(MSG_1, vbQuestion + vbOKCancel, _
MSG_TITLE) = vbOK Then
'Run the process
...
End If
 
Another angle to consider:

Select Case MsgBox( _
"Please verify that process did not run before continuing." & vbcrlf & _
"Press OK if you want to rerun the process, or click Cancel to abort.", _
vbOkCancel + vbExclamation, _
"Verify Process")
Case vbOk
'statements here
Case vbCancel
'statements here, frequently "Exit Sub"
End Select

Paul Johnson
 
Back
Top