Solved

Easy ComboBox question

Posted on 2002-06-25
8
141 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
Comment Utility
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
Comment Utility
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
Comment Utility
frmBenefits.cboFrm_Click (Ctrls.CboComponent)

Compile Error: Method or Data member not found.

Highlights:
".cboFrm_Click"
0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 18

Expert Comment

by:mdougan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

743 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