Solved

Easy ComboBox question

Posted on 2002-06-25
8
147 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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
 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

717 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