Restrict Entry of Dates in Access 2003

  • Thread starter Thread starter cleblanc
  • Start date Start date
C

cleblanc

I need to not allow a date to be entered into the "Date" field if the
entry date is greater than the 5th day of the current month.

Any help is appreciated.
 
If you have a field in a table or a control on a form named Date, change it.
Date is a reserved word. Using reserved words as names will cause problems.
To do what you want, use the Before Update event of the text box where you
enter the date:

Private Sub txtSomeDate_BeforeUpdate(Cancel As Integer)

If Not IsDate(Me.txtSomeDate) Then
MsgBox "Invalid Date Entered", vbExclamation
Cancel = True
ElseIf Day(Me.txtSomeDate) > 5 Then
MsgBox "Must be on or before the 5th of the month", vbExclamation
Cancel = True
End If
End Sub
 
"I need to not allow a date to be entered into the "Date" field if the
entry date is greater than the 5th day of the *current* month."

Dave's code only assures that the tstSomeDate is on or before the 5th of
*some* month, not neccessarily the current month. So we need to modify his
code to add validation to assure that the entered date is also the current
month and year:

Private Sub txtSomeDate_BeforeUpdate(Cancel As Integer)

If Not IsDate(Me.txtSomeDate) Then
MsgBox "Invalid Date Entered", vbExclamation
Cancel = True
ElseIf (Month(Me.txtSomeDate) <> Month(Date)) Or (Year(Me.txtSomeDate) <>
Year(Date)) Or (Day(Me.txtSomeDate) > 5) Then
MsgBox "Must be on or before the 5th of the month", vbExclamation
Cancel = True
End If
End Sub
 
Just had a stray thought (they come so seldom, I like to nuture them!) Do
your requirements need the entered date to be the 1st thru 5th of the current
month, or can a valid date be any day of any previous month as well?

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 
If you *do* require the ability to enter enter dates from the 5th of the
current month or EARLIER (i.e. any date before the 5th of the current month,
including dates from previous months) this will do it:

Private Sub txtSomeDate_BeforeUpdate(Cancel As Integer)
If Not IsDate(Me.txtSomeDate) Then
MsgBox "Invalid Date Entered", vbExclamation
Cancel = True
ElseIf Me.txtSomeDate > DateSerial(Year(Date), Month(Date), 5) Then
MsgBox "Must be on or before the 5th of the current month",
vbExclamation
Cancel = True
End If
End Sub

Just had a stray thought (they come so seldom, I like to nuture them!) Do
your requirements need the entered date to be the 1st thru 5th of the current
month, or can a valid date be any day of any previous month as well?

--
There's ALWAYS more than one way to skin a cat!

Answers/posts based on Access 2000

Message posted via AccessMonster.com
 

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