Error checking a date field

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

Guest

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.
 
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
 
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
 

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

Back
Top