×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Query Criteria Problem

Query Criteria Problem

(OP)
I have 2 fields Year and Month. They are both numeric and in YYYY and MM formats.
I’m trying to write a query that will select records that are less than the current date.

For Year I’m using <=Year(Date()).
For Month I’m using <Month(Date()).

Because we are in Feb, I’m only selecting records for Jan.

How would I change the Month criteria to select records like 11 or 12 for months from the previous year?

Kopy

RE: Query Criteria Problem

Quote (kopy)

select records like 11 or 12 for months from the previous year

Select *
From SomeTable
Where fldYear < Year(Date())
And fldMonth Between 11 And 12

---- Andy

There is a great need for a sarcasm font.

RE: Query Criteria Problem

Add field in a query: (12*[Year]+[Month]) and criteria <(12*Year(Date()+Month(Date())

combo

RE: Query Criteria Problem

I would try combine the fields.

Are your field names actually Year and Month? These are names of function (reserved words).

CODE --> SQL

WHERE YearField * 100 + MonthField < Year(Date()) * 100 + Month(Date())

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!