Link to home
Start Free TrialLog in
Avatar of jbauer22
jbauer22

asked on

Easy ComboBox question

I have a Wizard (wizBenefits) in my application.  When the user clicks Apply that triggers the ProcessResults procedure.  In this procedure I want to trigger the Click event on a ComboBox in another form (frmBenefits).  The form is loaded.  I need the previously selected item to remain selected too.  I think this can be done with the Index property but am tired of fooling around.

So I need something like this:

Private Sub ProcessResults()

     frmBenefits.cboComp...   <--- Trigger Click event?

End Sub

Jefferson
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jbauer22
jbauer22

ASKER

Actually, I have enums for for multiple combo boxes.
I get an error:  VB says the "_" is an invalid character.

frmBenefits.cboFrm(ctrls.CboComponent)_Click()

frmBenefits.cboFrm_Click (Ctrls.CboComponent)

Compile Error: Method or Data member not found.

Highlights:
".cboFrm_Click"
Then you would use:

frmBenefits.cboForm_Click ctrls.CboComponent

Again, it is probably private on the form, you can change the event to be declared Public though by replacing the Private Keyword with Public in the event declaration.
Tim:

Private Sub cboComp_Click()
'Move code from here to cboCompClick
cboCompClick
End Sub

Public Sub cboCompClick()
 'Put your code here
End Sub


You don't need to do this, VB will just let you change the Private to Public for the Combo's Click event:

Change this
Private Sub cboComp_Click()
'Your Code Here
End Sub

To this
Public Sub cboComp_Click()
'Your Code Here
End Sub


Then call it like this:
frmBenefits.cboComp_Click
If you wanted to have a Public sub on the other form that can have passed to it the name of a combo box and then you will call the click event for that combo box, then you can try something like this:

Private Sub Command1_Click()
    Form2.cboFrm Form2.Combo2
End Sub


Private Sub Combo1_Click()
    MsgBox "Combo1_Click"
End Sub

Private Sub Combo2_Click()
    MsgBox "Combo2_Click"
End Sub

Public Sub cboFrm(oCtrl As Control)

If oCtrl.Name = Combo1 Then
      Combo1_Click
ElseIf oCtrl.Name = Combo2 Then
      Combo2_Click
End If

End Sub

I agree, and did suggest this as well though perhaps not clearly. Even then it would be neater to make this a seperate sub and call it directly. Either way works just as well though.
Tim, I thought you were getting at something using the Controls collection.  I think that there might be some possibility with that, but I'm pretty unfamiliar with it.

Mike