Validation rule help, please

  • Thread starter msnews.microsoft.com
  • Start date
M

msnews.microsoft.com

What is the correct sytax to prevent a field from being left blank, only on
this form.??
This is what I have been trying in the validation property
<>"" Or Not "IsEmpty" Or Not "IsNull"

Thank you in advance for any and all help..
 
A

Allen Browne

Test if the value is Null.

You cannot do that in the Validation Rule of the control, since that rule
does not fire if nothing is entered there. Instead, use the BeforeUpdate
event of the *form* (not control.) Cancel the event to prevent the record
being saved.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[MyControl]) Then
Cancel = True
MsgBox "Can't save while MyControl is blank."
End If
End Sub
 
M

msnews.microsoft.com

BINGO!!! >> Of course... I did know that a long time ago and it makes so
much sense, as soon as I started to read your reply, I got to "the rule does
not fire" it all came back... Thank you very much...
What would I do with out this site....

Allen Browne said:
Test if the value is Null.

You cannot do that in the Validation Rule of the control, since that rule
does not fire if nothing is entered there. Instead, use the BeforeUpdate
event of the *form* (not control.) Cancel the event to prevent the record
being saved.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me.[MyControl]) Then
Cancel = True
MsgBox "Can't save while MyControl is blank."
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

msnews.microsoft.com said:
What is the correct sytax to prevent a field from being left blank, only
on this form.??
This is what I have been trying in the validation property
<>"" Or Not "IsEmpty" Or Not "IsNull"

Thank you in advance for any and all help..
 
Top