Solved

Easy ComboBox question

Posted on 2002-06-25
8
142 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:jbauer22
  • 3
  • 3
  • 2
8 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 40 total points
ID: 7107555
Just call the event procedure directly:

frmBenefits.cboComp_Click()

Though the event is probably declared private so you might be better off by moving the code from the existing Click event into a Public sub which can then be either called directly from your "external" procedure or from within the click event itself.

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

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

 
0
 
LVL 2

Author Comment

by:jbauer22
ID: 7107616
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()

0
 
LVL 2

Author Comment

by:jbauer22
ID: 7107632
frmBenefits.cboFrm_Click (Ctrls.CboComponent)

Compile Error: Method or Data member not found.

Highlights:
".cboFrm_Click"
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7107652
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 18

Expert Comment

by:mdougan
ID: 7107881
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
0
 
LVL 18

Expert Comment

by:mdougan
ID: 7107918
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

0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7107920
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.
0
 
LVL 18

Expert Comment

by:mdougan
ID: 7109408
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now