Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare date field to Part of current date

Status
Not open for further replies.

vfisher

Programmer
Apr 15, 2002
40
US
I'm using Access 97. I have a date field (format short date) on my form. I need to validate that the month/year of this field is not greater than the current month year.

I tried using datepart and format in every variation I could think of but I get an error everytime.

if I don't get a syntax error, I get a run time error "5", Invalid procedure call or argument.

I'm sure there's an easy way to do this, but I'm at a loss.
Any help will be greatly appreciated.
 
I setup a test form with a text control called DateField that I could enter any date into it. Then I setup a button with the following code in the OnClick event Procedure:
If (DatePart(&quot;m&quot;, Me![DateField]) <= DatePart(&quot;m&quot;, Date)) And (DatePart(&quot;yyyy&quot;, Me![DateField]) <= DatePart(&quot;yyyy&quot;, Date)) Then
MsgBox &quot;DateField is NOT greater than Todays MM/YY&quot;
Else
MsgBox &quot;DateField IS greater than Todays MM/YY&quot;
End If

This is just a demonstration. You can extract the IF statement and use it appropriately in your application.

Bob Scriver
 

I am assuming you want to test yy/mm in combination. For instance your test would accept 1/10/1999 when compared with todays date since 199901 is less then 200206.

Therefore, the test would be

If format(yourdate,&quot;yyyymm&quot;) < FORMAT(date(),&quot;yyyymm&quot;) = true ‘success

Try it in the instant window for proof.
Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top