Error checking a date field

I

Ian

I have a form collecting data on patients' operations in my hospital. I want
to be able to error check the date of operation entered for any inaccurate
data entry. If the date entered is in the future a message box alerts the
user to this. When they click OK they are taken to the next field in the tab
order whereas I'd like to take them back to the date field to re-enter the
correct date. Here's my code:

Private Sub DoOp_AfterUpdate()
If DoOp > Now() Then
MsgBox "You have entered a date in the future.", vbOKOnly, "Input
Error"
End If
End Sub

How can I return the user to the date field.

Thanks for any suggestions,
Ian.
 
B

Barry Gilbert

Instead of the AfterUpdate event, put your code in the BeforeUpdate event.
After the messagebox, put:
Cancel = True

This will cancel the update and keep the cursor in the current textbox.

Barry
 
I

Ian

Thanks for the help, works a treat.

Ian.

Barry Gilbert said:
Instead of the AfterUpdate event, put your code in the BeforeUpdate event.
After the messagebox, put:
Cancel = True

This will cancel the update and keep the cursor in the current textbox.

Barry
 
Top