Home All Groups Group Topic Archive Search About

How to check which button was clicked on?

Author
7 Jun 2009 5:58 PM
fred
Hello,
          I have a small Microsoft program, which at the setup time displays
the license agreement with OK and Cancel button.
I wonder, if there is some mechanism (return code) allowing me to check
which button was pressed?
Thanks,
Fred

Author
7 Jun 2009 6:59 PM
Rick Rothstein
>          I have a small Microsoft program, which at the setup time
> displays the license agreement with OK and Cancel button.
> I wonder, if there is some mechanism (return code) allowing me to check
> which button was pressed?

Although you didn't say, I'm assuming from your use of OK and Cancel
buttons, that you are displaying your license agreement using a MessageBox
with vbOKCancel as your Buttons argument. The key to what you want to do is
to use the MsgBox in its function version and assign the user's response to
a variable that can be tested (the use of a variable is not required, but my
personal opinion is that it makes the code "cleaner"). Generally, you would
do something like this...

Dim Answer As Long
......
......
Answer = MsgBox("Text", vbOKCancel + vbExclamation, "License")
If Answer = vbOk Then
   '  Put code here for when the user clicks the OK button
Else
  '  Put code here for when the user clicks the Cancel button
End If

or, to test in opposite order, do the If..Then..Else part like this...

If Answer = vbCancel Then
   '  Put code here for when the user clicks the Cancel button
Else
  '  Put code here for when the user clicks the OK button
End If

--
Rick (MVP - Excel)
Author
7 Jun 2009 7:12 PM
Nobody
Multiposted and answered in another group.