The HRWizard data file contains a worksheet named ListMgr that contains the
data for each list. The data is stored in named ranges on the ListMgr worksheet.
Our cListManager class will contain functions that let us populate our combo boxes from
these named ranges. We??™ll also add a method to bind a list to a VBA Collection object. This
concept could easily be expanded to include lists gathered from any data source (like XML) or
an ADO or DAO recordset.
Insert a new class module and name it cListManager. Add these two methods to the class:
Public Sub BindListToRange(ListRangeName As String, TheCombo As MSForms.ComboBox)
TheCombo.RowSource = ListRangeName
End Sub
Public Sub BindListToCollection(TheCollection As Collection, ??
TheCombo As MSForms.ComboBox)
Dim iNumItems As Integer
Dim i As Integer
iNumItems = TheCollection.Count
For i = 1 To iNumItems
TheCombo.AddItem TheCollection(i)
Next i
End Sub
The BindListToRange method takes a Range name string value and a ComboBox object,
and sets the ComboBox??™s RowSource property to the named range. The BindListToCollection
method simply loops through a collection and calls the ComboBox??™s AddItem method.
The Data Class
Our data class is named cHRData. This class is being designed specifically for our HRWizard
application, and will be closely coupled with our cPerson object and our EmpData worksheet.
Insert a new class module and name it cHRData. Add the following module-level variables, one
property, and one method:
Private m_oWorksheet As Worksheet
Private m_lngNewRowNum As Long
Private m_oEmployee As cPerson
Private m_oXL As cExcelUtils
'
Public Property Get Worksheet() As Worksheet
Set Worksheet = m_oWorksheet
End Property
Public Property Set Worksheet(newWorksheet As Worksheet)
Set m_oWorksheet = newWorksheet
End Property
CHAPTER 4 n USERFORMS 169
Public Function SaveEmployee(Employee As cPerson) As Boolean
Dim blnReturn As Boolean
If m_oWorksheet Is Nothing Then
GoTo Exit_Function
End If
m_lngNewRowNum = m_oXL.
Pages:
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178