Microsoft Office Tutorials and References
In Depth Information
Validating Data
' Test fields from bottom to top so the last focus is¶
' set on the first¶
If Not Len(Nz(Me.Phone)) > 0 Then¶
' No phonenumber¶
strMessage = strMessage & vbCrLf & “Phone number is required”¶
Me.Phone.BackColor = vbRed¶
End If¶
If Len(Nz(Me.DateStartMembership)) > 0 And
Len(Nz(Me.DateEndMembership)) > 0 Then¶
If Me.DateEndMembership < Me.DateStartMembership Then¶
' Enddate before Startdate ? !¶
strMessage = strMessage & vbCrLf & “End date needs to be
larger than start dateӦ
Me.DateEndMembership.BackColor = vbRed¶
End If¶
End If¶
If Not Len(Nz(Me.DateStartMembership)) > 0 Then¶
' No DateStartMembership¶
strMessage = strMessage & vbCrLf & “Date Start Membership is
Me.DateStartMembership.BackColor = vbRed¶
End If¶
If Not Len(Nz(Me.DOB)) > 0 Then¶
' No DOB¶
strMessage = strMessage & vbCrLf & “Date of Birth is required”¶
Me.DOB.BackColor = vbRed¶
End If¶
' test if an error has been found¶
If Len(strMessage) > 0 Then¶
' display message and don't close form¶
MsgBox strMessage¶
' Close form and Access will save the data¶
End If¶
End Sub¶
The strMessage field holds the concatenated error message(s). When this field
is empty, the conclusion is that there are no errors.
Note: Backcolors need to be reset when starting the test, and also when the Reset
button is selected.
Search JabSto ::

Custom Search