Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


How to link an event procedure of many objects to one procedure in vb6

Posted on 2004-10-27
Medium Priority
Last Modified: 2010-05-02
I have many comboboxes that need to listen for the GotFocus event.  In that event procedure the same code will be executed for each combobox.  I am trying to avoid having to code the same event for every combobox.  Is there a way to register all the comboboxes on a form with one event procedure without creating a control array?
Question by:superbeast23
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
  • 2
LVL 32

Expert Comment

ID: 12421575
You can call a common function from each ComboBox_GotFocus event, passing in a reference to which combo has the focus:

Private Sub DoComboStuff(cb as ComboBox)
    with cb
    .additem ...
    end with

End Sub

'And for each of the comboboxes:
Private Sub Combo1_GotFocus

    Call DoComboStuff(Combo1)

End Sub
LVL 86

Accepted Solution

Mike Tomlinson earned 500 total points
ID: 12421610
If you don't want to call a common event or use a control array, then the answer is no.

Upgrade to VB.Net for that capability.  =)

LVL 32

Assisted Solution

Erick37 earned 500 total points
ID: 12421678
Another way is to create a "helper" class which will receive the events of the combobox.  Here is a sample program which uses this method.  It requires code in each of the comboboxes Gotfocus events as well.

See this example:

Expand ComboBox choices while typing

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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.
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

604 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