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

  • Thread starter Thread starter Fletcher
  • Start date Start date
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.
 
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
 
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
 

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

Back
Top