The ID will be
pulled from the database as it??™s needed. Everything else is rather generic until we get to our
DBWorksheet property. This is where we are storing the worksheet that contains our database
and must be set before the class can work.
We??™re going to add a GetNextID method to find the last row, grab the value from the first
column, and then increment it by 1. This function will set the ID property??™s internal variable
so we can retrieve it from the class once it??™s set.
Add the following code to the cCustSurvey class module:
Public Function GetNextID() As Long
Dim lngReturn As Long
lngReturn = m_xlWksht.Cells(Rows.Count, 1).End(xlUp).Value + 1
m_lngID = lngReturn ' set the ID property
GetNextID = lngReturn
End Function
This code is very similar to the FindEmptyRow method in the cExcelUtils class, but it??™s
returning a cell value instead of a row number.
Next, add initialization and cleanup code:
Private Sub Class_Initialize()
Set m_oXL = New cExcelUtils
End Sub
Private Sub Class_Terminate()
Set m_oXL = Nothing
End Sub
nTip As mentioned in previous chapters, the Class_Initialize method is a great place to set up any
internal objects used by your custom classes, and the Terminate method is the place to clean these objects
up when you??™re finished using your class.
Now let??™s make this class do some work. First let??™s add some validation code. We cannot
save the record if the State and PhoneNumber properties do not contain data.
Pages:
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161