Running A Macro Based on Selection From Combo Box

S

Steven Patrick

How do I get a different macro to run based on each selection chosen from a
combo box? For example, if the user chooses selection 1 from the combo box,
macro 1 runs, if they choose selection 2 macro 2 runs, etc.
 
F

fredg

How do I get a different macro to run based on each selection chosen from a
combo box? For example, if the user chooses selection 1 from the combo box,
macro 1 runs, if they choose selection 2 macro 2 runs, etc.

A Macro? why not simply use code?

Use code in the Combo Box AfterUpdate event:

Display the Combo Box's property sheet.
Click on the Event tab.
Click on the event line you wish to code.
Write
[Event Procedure]
on that line.
Then click on the little button with the 3 dots that appears on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those lines write the following code.

If Me.ComboName = 1 Then
' Do whatever #1 should do here
Elseif Me.ComboName = 2 then
' Do whatever #2 should do here
Else
' Do whatever the #3 thing should do here
End If

Change ComboName to whatever the actual name of the control is.
Change ComboName = 1 to whatever the actual combo criteria should be.
Note: if it is a text selection, you must enclose the value within
quotes, i.e. If Me.ComboName = "New York" Then

If you must use an already existing Macro, you can use, in place of
' Do whatever #1 should do here, for example:
DoCmd.RunMacro "MacroName1"
etc.
but why not just use code for the entire event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top