PDA

View Full Version : Assign Macro to ComboBox??



selraith
11-10-2007, 03:49 PM
Hi is it possible to assign the a specific line within the combobox with a macro or even a code??

for example:
With Me.ComboBox1
.AddItem ("Package One")
Then assigning this with a maco (call module1.helpme) or Sheets("Boot Screen").Select

The full code can be seen below:

Option Explicit
Private Sub cmdCancel_Click()
'Unload the userform
Unload Me
End Sub
Private Sub cmdOkay_Click()
'Verify that an item was selected
If Me.ComboBox1.BoundValue = vbNullString Then
MsgBox "You did not choose an item!", vbOKOnly
Else
MsgBox "You choose " & Me.ComboBox1.BoundValue, vbOKOnly
End If
Unload Me
End Sub
Private Sub ComboBox1_Change()
End Sub
Private Sub UserForm_Initialize()
'Load the combobox with a variety of household pets
With Me.ComboBox1
.AddItem ("Package One")
.AddItem ("Package Two")
.AddItem ("Package Three")
.AddItem ("Package Four")
.AddItem ("Package Five")
.AddItem ("Package Six")
.AddItem ("Package Seven")
.AddItem ("Package Eight")
.AddItem ("Package Nine")
.AddItem ("Show All")
End With
End Sub


TIA
Thanks in Advance

mikerickson
11-10-2007, 04:06 PM
Perhaps something like

Private Sub ComboBox1_Change()
If Me.ComboBox1.ListIndex = 0 Then
Call module1.helpme
End If
End Sub

Norie
11-10-2007, 04:13 PM
I'm a little confused because I can't actually find a BoundValue property in Excel.:huh:

lucas
11-10-2007, 04:25 PM
From the help file:


Remarks
BoundValue applies to the control that has the focus.
The contents of the BoundValue and Value properties are identical most of the time. When the user edits a control so that its value changes, the contents of BoundValue and Value are different until the change is final.
Several things occur when the user changes the value of a control. For example, if a user changes the text in a TextBox, the following things occur:
The Change event is initiated. At this time the Value property contains the new text and BoundValue contains the previous text.

The BeforeUpdate event is initiated.

The AfterUpdate event is initiated. The values for BoundValue and Value are once again identical, containing the new text.
BoundValue cannot be used with a multi-select list box.

selraith
11-11-2007, 03:03 AM
but the problem is how do i make AddItem ("Package One") go to a different macro from package two and package tjree and so on?

Bob Phillips
11-11-2007, 03:39 AM
Private Sub ComboBox1_Change()
With Me.ComboBox1
If .ListIndex = 0 Then
Call macro1
ElseIf .ListIndex = 1 Then
Call macro2
'etc
End If
End With
End Sub

selraith
11-11-2007, 03:45 AM
it works Thank You Very Much the solution was:
Private Sub ComboBox1_Change()
If Me.ComboBox1.ListIndex = 0 Then
Sheets("Boot Screen").Select
ElseIf Me.ComboBox1.ListIndex = 1 Then
Sheets("Stage? Marketing Project 2.0").Select
End If
End Sub

Because i couldnt assign a macro i simply used the code that was stored within the module1 and module2 etc to be a sub for my macro and it works correctly... All i can say is thank you very much for all your help!!
That must mean drinks on me tonite :beerchug: ^^

Ivan F Moala
11-11-2007, 04:28 AM
Cross Posted...

You better inform the people @ Xtremevbtalk

http://www.xtremevbtalk.com/showthread.php?t=289935

that you have a solution .....

selraith
11-11-2007, 04:53 AM
oh yes thank you very much

Tezzies
11-18-2007, 12:22 PM
sry posted in the wrong place