cls file and choose the Open command.
CHAPTER 4 n USERFORMS 138
Figure 4-6. Importing a module
The cExcelUtils class is now a part of your project. Open the cExcelUtils class in the VBE
and add the following method. The FindEmptyRow function returns a Long Integer containing
the row number of the next available row on a worksheet.
Function FindEmptyRow(ws As Worksheet) As Long
Dim lngReturn As Long
lngReturn = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
FindEmptyRow = lngReturn
End Function
This simple bit of code uses the Range object??™s End property to find the last cell in the
region and offsets it by 1. We??™re passing in a worksheet as an argument so the function will
return the next open row in the passed worksheet.
The Working Class
Next we??™re going to build a class to hold the values for each customer survey. This class will
also store the location of the database worksheet and it will perform a data save to the
database.
In the VBE, add a new class module and name it cCustSurvey. Add the following modulelevel
variables to hold the various properties:
Private m_lngID As Long
Private m_strState As String
Private m_strPhone As String
Private m_blnHeardOfProduct As Boolean
Private m_blnWantsProduct As Boolean
Private m_blnFollowup As Boolean
Private m_xlWksht As Worksheet
Private m_oXL As cExcelUtils
The first six items are simply the data we??™ll enter on our UserForm plus the ID field that
we??™ll generate from the database worksheet.
Pages:
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159