View Single Post
  #1  
Old October 29th, 2008, 05:40 PM posted to microsoft.public.access
Bunky
external usenet poster
 
Posts: 374
Default Force Validation prior to leaving form.

I have a form that I am trying to validate some data and I do not want to
have the focus change to a new record until the old record is correct.
Initially, I had all the validation done on when the close button was clicked
and this worked fine. However, the operators can use the navigation arrows
to go to a new record as well which, of course, bypasses all my code. I then
put the validation code in the form on the Before Update event. This works
but after I get the message box to display and click ok, it moves to a new
record rather than go back and validate again. Here is my code.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(User) Then

MsgBox "Please Enter a Specialist."
End If

If IsNull(AttendDate) Then

MsgBox "Please Enter a valid Date."
End If

If IsNull(Comments) Then

MsgBox "Please Enter Comments."
End If

End Sub

How do I make the code stay in this routine until all data has been entered?
Obviously, I am not a VB coder and am picking this up OTJ. Any help is
appreciated.