Validation rule help, please

  • Thread starter Thread starter msnews.microsoft.com
  • Start date 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..
 
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
 
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..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top