Using alert messages yes, no, cancel buttons...

F

Fletcher

Hi, I have a command button on my form that preforms a task (of course
right?). The catch is that I have an alert message that I would like
to use to confirm or deny the action. On the alert messages, you can
have it display yes and no buttons. My question is how do you write
the code to make the yes button execute the command, and the no button
skip the command. I imagine that it would be an if-else statement, but
I dont' know what the if would be. If anyone would be gracious enough
to help me with this, I would appreciate it greatly.
 
J

jmonty

You need to capture the response in a variable first.
Responses are actually integers - lookup Msgbox Constants in Access help for
the full list of values.
Within the subroutine for the command button Click event, create a return
value field - integer, then compare it to the VBA constants vbYes, vbNo or
vbCancel:

Dim intReturnvalue as Integer
intReturnValue = MsgBox("Prompt", vbYesNo + vbQuestion, "Title")
If intReturnValue = vbYes then
'Execute code here
Else
'Do nothing or Exit Sub here
Endif

jmonty
 
F

Fletcher

Very nice...thank you.
jmonty said:
You need to capture the response in a variable first.
Responses are actually integers - lookup Msgbox Constants in Access help for
the full list of values.
Within the subroutine for the command button Click event, create a return
value field - integer, then compare it to the VBA constants vbYes, vbNo or
vbCancel:

Dim intReturnvalue as Integer
intReturnValue = MsgBox("Prompt", vbYesNo + vbQuestion, "Title")
If intReturnValue = vbYes then
'Execute code here
Else
'Do nothing or Exit Sub here
Endif

jmonty
 
Top