Consulting

Results 1 to 3 of 3

Thread: Solved: Many comboboxes with one name

  1. #1

    Exclamation Solved: Many comboboxes with one name

    Greetings!

    I have a problem ... I'm creating a program that needs to load 60 comboxes with certain data. Actally, this data is coming from an array, and it works well when I load 1 combo box.

    My question is how can I utilize the object-oriented capabilities of vba to have all the comboboxes just going to one sub routine?

    In other words, I would like to have a generic name for all the combo boxes, so they all go to the same sub routine instead of going to 60 dofferent ones.

    Thank you very much!


    Eduardo

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Create a class called clsUserFormEvents with this code

    [vba]

    Option Explicit

    Public WithEvents mComboGroup As msforms.ComboBox

    Private Sub mComboGroup_Click()
    MsgBox mComboGroup.Value & " has been pressed"
    End Sub
    [/vba]

    and then add this to your vform

    [vba]


    Dim mcolEvents As Collection

    Private cCboEvents As clsUserFormEvents

    Private Sub UserForm_Initialize()
    Dim ctl As msforms.Control

    Set mcolEvents = New Collection

    For Each ctl In Me.Controls
    If TypeName(ctl) = "ComboBox" Then
    Set cCboEvents = New clsUserFormEvents
    Set cCboEvents.mComboGroup = ctl
    mcolEvents.Add cCboEvents
    End If
    Next
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thank you so much! I really appreciate it.

    Eduardo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •