MsgBox Function

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
 
J

John Nurick

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
 
P

Paul Johnson

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
 

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

Top