• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 131
  • Last Modified:

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 ?
1 Solution
Give the controls the same names with different index values.
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

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?


Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now