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

Posted on 2004-10-27
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
    LVL 32

    Expert Comment

    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 85

    Accepted Solution

    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

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: JavaScript Coding - Massive 12-Part Bundle

    Regardless of your programming skill level, you'll go from basics to advanced concepts in a vast array of JavaScript subjects including Sammy.js, Agility.js, Ember.js, Node.js, jQuery, AJAX, Extjs, AngularJS, Knockout.js, and JSON.

    Introduction In a recent article ( 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…
    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 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…

    884 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

    20 Experts available now in Live!

    Get 1:1 Help Now