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¶
Me.Phone.SetFocus¶
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¶
Me.DateEndMembership.SetFocus¶
End If¶
End If¶
If Not Len(Nz(Me.DateStartMembership)) > 0 Then¶
' No DateStartMembership¶
strMessage = strMessage & vbCrLf & “Date Start Membership is
requiredӦ
Me.DateStartMembership.BackColor = vbRed¶
Me.DateStartMembership.SetFocus¶
End If¶
If Not Len(Nz(Me.DOB)) > 0 Then¶
' No DOB¶
strMessage = strMessage & vbCrLf & “Date of Birth is required”¶
Me.DOB.BackColor = vbRed¶
Me.DOB.SetFocus¶
End If¶
' test if an error has been found¶
If Len(strMessage) > 0 Then¶
' display message and don't close form¶
MsgBox strMessage¶
Else¶
' Close form and Access will save the data¶
DoCmd.Close¶
End If¶
End Sub¶
Acs
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