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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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 Architect / Systems AnalystCommented:

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

mx
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
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
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?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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

mx
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.
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
standby ...

mx
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
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

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.
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.