×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

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

Students Click Here

Jobs

Query Criteria Problem

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?

Thank you in advance for your help,
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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close