Step 7 of 7
Now it is time to add validation
code. In order for the validation to prevent the data from being saved, an
error must be raised to let the calling function know that the data can't be
saved.
Validation code
Ultimately, validation is handled by the cTable.cls class module. However, the class simply validates that the data entered in a field
is of the type defined for the field. You must add your own validation code if you
want to check that certain entries fall within a range of values.
In this example we do not want to
let the user save the data unless there is text in both the Quote field and the
Author field.
We previously set the Required property of
each field to True so this code is not necessary. However, this is
the best place to validate user input before saving the record.
' frmDatabase.frm
Private Function Validate() As Long
On Error GoTo errHandler
If (Trim$(txtQuote.Text) = vbNullString) Or
(Trim$(txtAuthor.Text) = vbNullString) Then
Err.Raise APPLICATION_ERROR.ERR_REQUIRED_DATA_NOT_ENTERED
End If
Exit Function
errHandler:
Validate = Err
End Function |
|