How do I add a Yes/No button to a Macro?

kilroyscarnival

Registered User.
Local time
Today, 06:00
Joined
Mar 6, 2002
Messages
76
I have a message box popping up before my macro runs. I would like to modify that to give the user a choice to cancel. In other words, two option buttons, one saying "OK" and the other "CANCEL". I'm enough of a beginner to be clueless as to how to do this. Can I do it in a Macro or will I have to convert to a Module? Thanks for your help!

--Ann
 
A yes/no dialogue box is created thru vba.

To make a dialog box with yes/no:

Where you would assign a macro to an event, right click on the build button and select code builder.

Between you lines put:


Dim UserResponse As Integer


UserResponse = MsgBox("Your message here!", vbYesNo, "YOUR TITLE FOR THE BOX HERE")

If UserResponse = vbYes Then

'Your command for a yes answer goes here

Else

'Your command for a no answer goes here

End If


Hope that gets you started!
 
Perfect! Thank you. I'll bet there's a good book for this stuff, but the one I'm using is "Sams Learn MS Access in 21 Days", which doesn't go into a lot of this. Thanks!

I've already converted my macro to a module. What I couldn't figure out THEN was how to add my module to the Switchboard I had built. So I wrote a second Macro that basically says "Run Code" for the Module I wrote. Silly, isn't it? I'm sure there's a better way.

Now, I just went downstairs to train my accounting pals on how to do the updates. And the Switchboard won't open on Janice's computer! It gave me a code error I didn't have time to copy down -- before we were interrupted with an "accounting emergency." I thought I was in the database at my desk, maybe, but I wasn't. It still works fine from here. Any idea why?

-Ann
 
Try sams taech urself in 24 hrs. its a bit more basic and does cover the basics of message boxes etc. i think you can view portions of it on informit.com

i may be wrong on the last bit
 
Thank you again. I've been pulled away on other projects and recently down with the flu so I'm just getting back to your message. I appreciate it! -- A
 

Users who are viewing this thread

Back
Top Bottom