View Single Post
Old 10-06-2015, 11:34 AM   #12
Snowflake68
Newly Registered User
 
Join Date: May 2014
Location: Hampshire, England
Posts: 378
Thanks: 240
Thanked 4 Times in 4 Posts
Snowflake68 is on a distinguished road
Re: Run Yes/No MessageBox from MACRO

Quote:
Originally Posted by AccessJunkie View Post
Hi,

Could you please let us know which version of Access you are using? That will definitely help people replying to your question.

To answer your original question, yes you can certainly display a Yes/No message box from a macro and then take different action on what button is clicked.

In Access 2010, conditional logic in macros is way easier than previous versions, but it is still possible in previous versions; it's just a little more tricky.

Here's a quick example using Access 2007 in case you are using that version.

For the first line of this sample macro, enter this in the Condition column:

6<>MsgBox("Please click one of the buttons.",52)

In the Action column on the first time, use the MsgBox macro action and display a message that says "You clicked No."

On the second line of this macro, enter three dots ... in the Condition column to apply the condition from the previous line. In the Action column for the second line, use the StopMacro action.

On the third line of this sample macro, don't put anything in the Condition column. In the Action column of this third line, use the MsgBox macro action and display a message that says "You clicked Yes."

Save the macro and then run it to try it out.
You'll get a Yes/No message prompt that asks you to click a button. If you click the No button, you'll see a message box saying you clicked No and then the macro stops. If you click Yes, you'll see a message box saying you clicked Yes and then the macro stops.

In the sample example I provided, I used Yes/No buttons, a warning message box (the one with the exclamation point icon), and I was testing to see if they clicked the Yes button. You can modify this to present different options using the MsgBox function.

Hope that helps,

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

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
----------
Hi can I ask what the 52 refers to in this code?
6<>MsgBox("Please click one of the buttons.",52)
I have been trying to find a list of codes so that I can change the icon type and title but cannot find any reference to 52.
Snowflake68 is offline   Reply With Quote