Limit Max Value in Date Fields

K

Karl Burrows

I am trying to limit date entries in a form to prevent data entry errors. I
want to be able to allow up to today's date only and any value greater than
today will return an error. Too many people getting in a hurry and getting
dates in 2007, etc. Thanks!
 
K

Ken Snell [MVP]

You could use the BeforeUpdate event of the textbox to validate the date
entry to test that it's not greater than today:

Private Sub TextBoxName_BeforeUpdate(Cancel As Integer)
If Me.TextBoxName.Value > Date() Then
MsgBox "Invalid date!"
Cancel = True
End If
End Sub
 
K

Karl Burrows

Can I just create a Validation Rule in the field properties to say <Date()?

You could use the BeforeUpdate event of the textbox to validate the date
entry to test that it's not greater than today:

Private Sub TextBoxName_BeforeUpdate(Cancel As Integer)
If Me.TextBoxName.Value > Date() Then
MsgBox "Invalid date!"
Cancel = True
End If
End Sub
 
G

Graham Mandeno

Hi Karl

Yes, you can, but if you want to allow today's date also you will need <=
 

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

Top