Solved

Easy ComboBox question

Posted on 2002-06-25
8
144 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 40
using Access 8 75
Sending a email via excel using vba 6 96
Set WorkSheet  not Working 9 38
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

792 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