Yes/No msgbox

I currently have a button with an onclick event that runs a sub with s number of queries and then exports a file.

I'd like to add a y/n msgbox that appears when the button is first clicked.  If user selects yes, I want it to run the sub with all the queries.  If no, then I don't want to run it.  How is this done?
vsllcAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:

 If MsgBox("Do you want to run the queries?", 36, "Run Queries ?") = vbYes Then
    ' call your Sub here
 End If
 

mx
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Inside your button:

Private Sub btnRun_Click()

 If MsgBox("Do you want to run the queries?", 36, "Run Queries ?") = vbYes Then
    ' call your Sub here
 End If
 
End Sub


mx
0
vsllcAuthor Commented:
OK, the sub I want to run is currently my _Click.  Do I just remove that from the sub name?

When you say 'call sub here, how is that done?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
OK ... show me the code you have so far on your Click event ..

mx
0
vsllcAuthor Commented:
I'm on a mobile...short and sweet here's a sample.

Private Sub runsales_click()
Docmd.setwarnings False
Docmd.openqry "salesbymonth", acviewnormal, acedit
Docmd.setwarnings True
End sub

Have not put in the msgbox code yet.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
standby ...

mx
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
How about this:

Private Sub runsales_click()

If MsgBox("Do you want to run the queries?", 36, "Run Queries ?") = vbYes Then
     Docmd.setwarnings False
     Docmd.openquery "salesbymonth", acviewnormal, acedit
     Docmd.setwarnings True
End If

End sub

btw ... is salesbymonth an Action query (update, append, etc) ?

mx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vsllcAuthor Commented:
Cool, so just nest the sub in the if/then.

This worked perfectly!

Yes, the qry is an update qry.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.