macro

  • Thread starter Thread starter kendra lewin
  • Start date Start date
K

kendra lewin

Is it possible to assign unique macros to individual items
in a "combo drop down box"? For example, I have 5 items
that a user can select in a combo box. I can only assign
one macro. This same macro runs for every selection. I
want to have a unique macro run depending on the selection.
 
Kendra,

You can create your 5 macros, lets say for arguments sake
they were macro1, macro2, ... macro5
You can use your combobox change event to run those 5
macros (so essentially each item has it's own macro, but
they are all fired from the same Combobox_Change event)

If you had Combobox1 and all the names of the possible
selections were "Item1", "Item2", ... "Item5" (ie that's what
the user clicks on).

And here I would like to suggest that
since you are using a combobox change event, you may
want to set the Style property of your combobox to
fmStyleDropDownList (disallows user typing in an input and
avoids the combobox change event from firing each time a
character is typed in the combobox. NOTE: I've assumed
that you used a combo box from the control toolbox not
the forms toolbox.

Anyways, here is the sample code...

Private Sub ComboBox1_Change()
UserIn = ComboBox1.Value
A = ComboBox1.Index
Select Case UserIn
Case "Item1"
Macro1
Case "Item2"
Macro2
Case "Item3"
Macro3
Case "Item4"
Macro4
Case "Item5"
Macro5
End Select
End Sub

Please note that the macros should be placed in the same
code window as the combobox change event.

Dan E
 
Back
Top