Validation Rule Not Working

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

On a form, field controls of several fields have the Validation Rule set to
"is Not Null" . The fields in the underlying table do allow null. The form
validation rules do not appear to be working as the form is allowing those
fields to be tabbed through without any error message popping up. The form
allows whole records to be added with those fields set to null without any
errors popping up.

Has anybody run across this before? Its there a global setting that is
being missed?

Thanks

Trish
 
Hi Trish

Access applies the validation rule for a text box whenever you enter
something there. If you don't visit the text box or start making an entry,
there the rule is never triggered.

Use the BeforeUpdate event of the *form* to check for nulls. This example
shows how to do that for several fields at once:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg As String

If IsNull(Me.SomeField) Then
Cancel = True
strMsg = strMsg & "SomeField required." & vbCrLf
End If

If IsNull(Me.AnotherField) Then
Cancel = True
strMsg = strMsg & "AnotherField required." & vbCrLf
End If

'etc.

If Cancel Then
strMsg = strMsg & "Correct the entry, or press Esc to undo."
MsgBox strMsg, vbExclamation, "Invalid data"
End If
End Sub
 
Back
Top