Macro MessageBox options

Eljefegeneo

Still trying to learn
Local time
Today, 07:10
Joined
Jan 10, 2011
Messages
902
Using Microsoft Access 2010
I have a command button that runs a macro with the following:
If [MsgBox ("Do You Want to Close Form?", 4, "Form Closure") = 6
Run Code [MsgBox ("You Checked Yes")
Close Window
Form
FrmHistory
Save Prompt
Else
Run Code [MsgBox("You Checked No")
Stop Macro
End If

This works fine with only two options. But, If I use:
If [MsgBox ("Do You Want to Close Form?", 3, "Form Closure") = 6, giving me three variables, Yes, No and Cancel, I cannot figure out how to get the proper responses if No or Cancel are checked.

I have tried the attached, but it only brings up the message box "Cancel", never the "No"

What am I doing wrong?

It seems so easy in VBA, but I want to do it in a Macro. Thanks.
 

Attachments

  • MacroProblem.jpg
    MacroProblem.jpg
    89.4 KB · Views: 815
I would suggest converting this to VBA.
Easier to troubleshoot and work with.

Dale
 
Thank you for your reply. I "thought" it would be easier in VBA but it wasn't. Do you have any idea how to have three choices using the MsgBox function? I kept getting the same result as with the macro.
 
I've seen this page. It really doesn't answer my question. Which is, can you use a Message Box to have more than two selections and then depending on which selection you choose, come up with a different result. For example, Yes,No,Other, Yes would mean do some other action like print a report, No would mean cancel and Other would mean do a third action such as open another report.
 
Hi,

Since you are trying to capture three different types of responses, I would change your macro logic to first capture their response from the MsgBox to a temporary variable and then test the value of the temporary variable in the If block.

See my attached screenshot of example logic which works just fine in my simple test.

--------------------
Jeff Conrad - Access Junkie - MVP Alumnus
SDET II - Access Test Team - Microsoft Corporation

Author - Microsoft Access 2013 Inside Out (coming soon)
Author - Microsoft Access 2010 Inside Out
Co-author - Microsoft Office Access 2007 Inside Out
Access 2007/2010 Info: http://www.AccessJunkie.com

----------
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.mspx
----------
 

Attachments

  • MacroLogic.png
    MacroLogic.png
    17.3 KB · Views: 864
Thank you. I knew there was a way. As an interesting sidelight, when I tried to do the same in VBA using If statements, I could only get two of the variables to work correctly. But when I tried using Select Case, it worked fine.
For example, the following works fine:
Select Case MsgBox("Three Things to do", vbYesNoCancel)
Case vbYes
MsgBox "yes"
CasevbNo
MsgBox "No"
Case Else
MsgBox "Cancel"
End Select

Trying the same with If statements produced nothing but headaches.

Thanks for you input. Another lesson learned. And is much appreciated.
 

Users who are viewing this thread

Back
Top Bottom