Macro Yes / No

hcabs99

Active Member
Joined
May 9, 2006
Messages
257
Hi All

I have a macro set up which runs a number of queries etc from a button click on a form.

Would like the user to be given a message box pop up to be asked if he wishes to continue. If yes, then it should continue to run the macro. If no, then it should stop

Am using Access 2010, i understand that this process has been simplified in this version, but I've not been able to get this to work!

Any help would be appreciated

Cheers
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Macros are very limited and not really interactive (at least not without incorporating some VBA into it).
Access has a create utility that will convert your Macros to Visual Basic code (take a look at the Macros Menu/Ribbon). Use this to convert your Macros to VBA. Then you can edit that code and add your MsgBox and an IF ... THEN clause.

Then you can run this VBA code from a myriad of different ways. I often like to use a Command Button on a Form, or attach the code to the ****** event of some Form (so that it runs whenever a Form is opened). If I want it to run automatically, then I just make that Form the Startup Form for my database.
You might also be able to run it using the "RunCode" Macro action.
 
Upvote 0
Macros are very limited and not really interactive (at least not without incorporating some VBA into it).
Access has a create utility that will convert your Macros to Visual Basic code (take a look at the Macros Menu/Ribbon). Use this to convert your Macros to VBA. Then you can edit that code and add your MsgBox and an IF ... THEN clause.

Then you can run this VBA code from a myriad of different ways. I often like to use a Command Button on a Form, or attach the code to the ****** event of some Form (so that it runs whenever a Form is opened). If I want it to run automatically, then I just make that Form the Startup Form for my database.
You might also be able to run it using the "RunCode" Macro action.

Hi Joe,
Thanks for your help,

I'm aware of the function to covert to code and have been playing with this to make it work,

I want the user to be asked if he wishes to continue and have the Yes / No box now, however i'm not sure how to stop all macros running if No is selected.

Function TestMacro1()
On Error GoTo TestMacro1_Err

DoCmd.SetWarnings False
Beep
MsgBox "Do you wish to continue?", 4, ""
DoCmd.OpenQuery "Create_Buying_List_Prt4", acViewNormal, acEdit


TestMacro1_Exit:
Exit Function

TestMacro1_Err:
MsgBox Error$
Resume TestMacro1_Exit

End Function
 
Upvote 0
You can set conditional responses to message box queries as follows

Code:
If MsgBox("Do you want to do stuff?", vbYesNo) = vbYes Then
    'Do Stuff
Else
    'Don't do that stuff
End If
 
Upvote 0
Here is an example of code that will exit the whole VBA code if they elect No.
Code:
    myCheck = MsgBox("Do you wish to continue", vbYesNo)
    If myCheck = vbNo Then Exit Sub
 
Upvote 0
You can set conditional responses to message box queries as follows

Code:
If MsgBox("Do you want to do stuff?", vbYesNo) = vbYes Then
    'Do Stuff
Else
    'Don't do that stuff
End If

perfect, thanks v much for your help!
 
Upvote 0
You can set conditional responses to message box queries as follows

Code:
If MsgBox("Do you want to do stuff?", vbYesNo) = vbYes Then
    'Do Stuff
Else
    'Don't do that stuff
End If

This totally helped me with a question that I had as well.

Thanks so much!!
 
Upvote 0

Forum statistics

Threads
1,221,847
Messages
6,162,380
Members
451,760
Latest member
samue Thon Ajaladin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top