data validation in forms

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

Guest

I am still struggling with data validation at the control
level when adding new data to a form (a new record). Following up on an
earlier thread, I am using the BeforeUpdate property with
the following code (almost straight out of the book)

Private Sub PatientFName_BeforeUpdate(Cancel As Integer
If PatientFName = "" The
MsgBox "First Name cannot be blank
Me!PatientFName.Und
Cancel = Tru
End I
End Su

However you can still tab or click out of the control
without triggering the error statement. What am I doing
wrong

da
 
I am still struggling with data validation at the control
level when adding new data to a form (a new record). Following up on an
earlier thread, I am using the BeforeUpdate property with
the following code (almost straight out of the book):

Private Sub PatientFName_BeforeUpdate(Cancel As Integer)
If PatientFName = "" Then
MsgBox "First Name cannot be blank"
Me!PatientFName.Undo
Cancel = True
End If
End Sub

However you can still tab or click out of the control
without triggering the error statement. What am I doing
wrong.

As far as that goes, the user could simply never setfocus to the
control at all!

Use the Form's BeforeUpdate event instead. The textbox's event will
fire only if the user changes something in the textbox, so this code
would work only if they typed something into the box and then erased
it.
 
Back
Top