Stop Code From Running

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I stop code from running if the user clicks on YES?

Example: When the field gets focus, I might automatically insert data into
the field from a DLookUp execution. The intOptions = vbQuestion + vbYesNo. If
the user clicks YES, I might execute code in the EXIT event. As a result, I
want all the other code in different events (i.e., EXIT, AFTERUPDATE, etc.)
from running.

Thanks in advance for any assistance.

Rick
 
To register what button the user clicked on, you need to use MsgBox as a
function.

If MsgBox("Message to user", vbQuestion + vbYesNo) = vbYes Then
' User clicked on Yes
Else
' User clicked on No
End If
 
Douglas,

Thank you for your response. I must not have made myself to clear.

I do have code running in the background for the vbYes or vbNo options. What
I need is to write something behind the vbYes that would stop ALL OTHER EVENT
PROCEDURE codes (i.e., EXIT, AFTER UPDATE, BEFORE UPDATE, ON LOST FOCUS,
etc.) from running. I tried the DoCmd.CancelEvent but that does not work.

Thanks,

Rick
 
Sorry, but you can't have code running in the background. MsgBox is modal,
so all code stops running until the box is dismissed.

If you're saying that partway through your code, you have a message box and
you don't want the rest of the code in the routine to run, you'd use:

' code before msgbox
If MsgBox(....) <> vbYes Then
' rest of the code
End If

You could also use

' code before msgbox
If MsgBox(....) = vbYes Then
Exit Sub
Else
' rest of the code
End If

but I don't consider that to be good style.
 
Back
Top