How do I write a Criteria to search by month??

J

Joe Leon

In a table, along with other information in the record I have a field with
dates (short date) ... below I'm showing the column of three records.

11/01/07
11/10/06
01/11/08

I want to build a query to search by month so that when prompted, I enter
11, then I want the 11/01/07 and 11/10/06 to appear but not the 01/11/08.



What is the best way to write the criteria in the query so that is searches
by the number of the month?

I tried: Like [Enter Month] & DateSerial(Year(Date())+1,1,1)
but it's not working at all. All I get is the prompt but when I enter 11 no
records show.

THANKS! ... Joe....
 
F

fredg

In a table, along with other information in the record I have a field with
dates (short date) ... below I'm showing the column of three records.

11/01/07
11/10/06
01/11/08

I want to build a query to search by month so that when prompted, I enter
11, then I want the 11/01/07 and 11/10/06 to appear but not the 01/11/08.

What is the best way to write the criteria in the query so that is searches
by the number of the month?

I tried: Like [Enter Month] & DateSerial(Year(Date())+1,1,1)
but it's not working at all. All I get is the prompt but when I enter 11 no
records show.

THANKS! ... Joe....

Simply add a new column to the query grid.
TheMonth:Month([DateFieldname])

As criteria for this column, write:
[Enter Month Number]
 
J

Joe Leon

Hi said:
Simply add a new column to the query grid.
TheMonth:Month([DateFieldname])

As criteria for this column, write:
[Enter Month Number]

Are you saying to make a dedicated column for the month?
Thanks,
Joe...

fredg said:
In a table, along with other information in the record I have a field with
dates (short date) ... below I'm showing the column of three records.

11/01/07
11/10/06
01/11/08

I want to build a query to search by month so that when prompted, I enter
11, then I want the 11/01/07 and 11/10/06 to appear but not the 01/11/08.

What is the best way to write the criteria in the query so that is searches
by the number of the month?

I tried: Like [Enter Month] & DateSerial(Year(Date())+1,1,1)
but it's not working at all. All I get is the prompt but when I enter 11 no
records show.

THANKS! ... Joe....

Simply add a new column to the query grid.
TheMonth:Month([DateFieldname])

As criteria for this column, write:
[Enter Month Number]
 
R

Ron2006

Hi said:
Simply add a new column to the query grid.
TheMonth:Month([DateFieldname])
As criteria for this column, write:
[Enter Month Number]

Are you saying to make a dedicated column for the month?
Thanks,
Joe...



fredg said:
In a table, along with other information in the record I have a field with
dates (short date) ... below I'm showing the column of three records.
11/01/07
11/10/06
01/11/08
I want to build a query to search by month so that when prompted, I enter
11, then I want the 11/01/07 and 11/10/06 to appear but not the 01/11/08.
What is the best way to write the criteria in the query so that is searches
by the number of the month?
I tried: Like [Enter Month] & DateSerial(Year(Date())+1,1,1)
but it's not working at all. All I get is the prompt but when I enter 11 no
records show.
THANKS! ... Joe....
Simply add a new column to the query grid.
TheMonth:Month([DateFieldname])
As criteria for this column, write:
[Enter Month Number]

- Show quoted text -

The column that Fred is creating is a "temporary" field that is
created dynamically and exist ONLY in the query.

If you use the query builder
1) select all the fields from the table that you want to see in the
query.
2) go to the next open column and enter what Fred suggested.
TheMonth:Month([DateFieldname])
3) As the criteria for the column enter
[Enter Month Number]

When you run the query you will see all the columns you have selected
from the table AND you will see a column labelled "TheMonth"

Queries can include all sorts of calculated/partial fields in that
same manner.

Ron
 
J

Joe Leon

Thank you Fred and Ron ! It works great!

Ron2006 said:
Hi said:
Simply add a new column to the query grid.
TheMonth:Month([DateFieldname])
As criteria for this column, write:
[Enter Month Number]

Are you saying to make a dedicated column for the month?
Thanks,
Joe...



In a table, along with other information in the record I have a field with
dates (short date) ... below I'm showing the column of three records.

I want to build a query to search by month so that when prompted, I enter
11, then I want the 11/01/07 and 11/10/06 to appear but not the 01/11/08.
What is the best way to write the criteria in the query so that is searches
by the number of the month?
I tried: Like [Enter Month] & DateSerial(Year(Date())+1,1,1)
but it's not working at all. All I get is the prompt but when I enter 11 no
records show.
THANKS! ... Joe....
Simply add a new column to the query grid.
TheMonth:Month([DateFieldname])
As criteria for this column, write:
[Enter Month Number]

- Show quoted text -

The column that Fred is creating is a "temporary" field that is
created dynamically and exist ONLY in the query.

If you use the query builder
1) select all the fields from the table that you want to see in the
query.
2) go to the next open column and enter what Fred suggested.
TheMonth:Month([DateFieldname])
3) As the criteria for the column enter
[Enter Month Number]

When you run the query you will see all the columns you have selected
from the table AND you will see a column labelled "TheMonth"

Queries can include all sorts of calculated/partial fields in that
same manner.

Ron
 
R

Ron2006

If you end up having more than one year's information in that table,
you may want to add the year to that query in much the same manner. or
combined.

Ron
 

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