Create a class for listbox filling...

I have 4 simple-list style combo boxes containing the names of date fields
and they are all on the same form.  They all contain the exact same information.  I ought to be able to create a "Class" for them, shouldn't I?  Then I could define it just once and replicate, right?  Any ideas ?
provb6dbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jon_RaymondCommented:
Give the controls the same names with different index values.
0
TigerZhaoCommented:
use a class to share code is right.
### Ccbo ###
Option Explicit

Public WithEvents cbo As ComboBox

Private Sub cbo_Change()
    ' Do something
End Sub

Private Sub Class_Terminate()
    Set cbo = Nothing
End Sub
### Form1 ###
Option Explicit

Private clscbo1 As Ccbo
Private clscbo2 As Ccbo
Private clscbo3 As Ccbo
Private clscbo4 As Ccbo

Private Sub Form_Load()
    Set clscbo1 = New Ccbo
    Set clscbo1.cbo = Combo1
    Set clscbo2 = New Ccbo
    Set clscbo2.cbo = Combo2
    Set clscbo3 = New Ccbo
    Set clscbo3.cbo = Combo3
    Set clscbo4 = New Ccbo
    Set clscbo4.cbo = Combo4
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set clscbo1 = Nothing
    Set clscbo2 = Nothing
    Set clscbo3 = Nothing
    Set clscbo4 = Nothing
End Sub

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
provb6dbAuthor Commented:
I like the idea here and I think it will work but it seems like there should be more code. I named the new class module Ccbo which got rid of the type not defined error but how would I use this class to fill the comboboxes with data?

Jason
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.