Add a new function
called ValidateData and type in the following code:
CHAPTER 4 n USERFORMS 141
Public Function ValidateData() As Boolean
Dim blnReturn As Boolean
If (Len(Me.PhoneNumber & "") * Len(Me.State & "")) = 0 Then
blnReturn = False
Else
blnReturn = True
End If
ValidateData = blnReturn
End Function
By multiplying the lengths of the text values State and PhoneNumber, we can determine
whether one is missing, because the math will always return 0 if we??™re multiplying by 0.
Create a new function named Save that returns a success flag. This function needs to
know the row number of the next available row for data entry; it needs to know what sheet
that row is on; and if there are no errors, it must return a Boolean True value.
Here is the code for the Save method:
Public Function Save() As Boolean
Dim lngNewRowNum As Long
Dim blnReturn As Boolean
If m_xlWksht Is Nothing Then
blnReturn = False
GoTo Exit_Function
End If
lngNewRowNum = m_oXL.FindEmptyRow(m_xlWksht)
With m_xlWksht
.Cells(lngNewRowNum, 1).Value = Me.ID
.Cells(lngNewRowNum, 2).Value = Me.State
.Cells(lngNewRowNum, 3).Value = Me.PhoneNumber
.Cells(lngNewRowNum, 4).Value = Me.HeardOfProduct
.Cells(lngNewRowNum, 5).Value = Me.WantsProduct
.Cells(lngNewRowNum, 6).Value = Me.Followup
End With
If Err.Number = 0 Then
blnReturn = True
End If
Exit_Function:
Save = blnReturn
Exit Function
End Function
CHAPTER 4 n USERFORMS 142
The first thing we??™re doing is checking to make sure our worksheet object still exists.
Pages:
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162