Sorting by month

K

Kathi

I have a field in my database for a surgery date and the month, day, and year
are all part of one field. Now a user wants to be able to query by the
month. It's been too long since I took the class and I don't use it often
enough to know how to write a query to make this happen. Can anyone help me?
 
J

John W. Vinson

I have a field in my database for a surgery date and the month, day, and year
are all part of one field. Now a user wants to be able to query by the
month. It's been too long since I took the class and I don't use it often
enough to know how to write a query to make this happen. Can anyone help me?

Is this an Access Date/Time field? If so, you can use a criterion like
= DateSerial([Enter year:], [Enter month number:], 1) AND < DateSerial([Enter year:], [Enter month number:]+1, 1)

Entering 2009 for the year and 5 for the month will get all records in May.

If the date is stored in some other datatype post back with more details and
perhaps an example.
 
K

Kathi

That almost works. What this person really wants is to be able to see
everyone who had surgery during each month of all the years. So I want to
just put in the month but not the year. I tried deleting the "Enter year"
part of what you gave me and it won't accept it. Can you give me another one
that will just ask for the month?

Thanks. kf

John W. Vinson said:
I have a field in my database for a surgery date and the month, day, and year
are all part of one field. Now a user wants to be able to query by the
month. It's been too long since I took the class and I don't use it often
enough to know how to write a query to make this happen. Can anyone help me?

Is this an Access Date/Time field? If so, you can use a criterion like
= DateSerial([Enter year:], [Enter month number:], 1) AND < DateSerial([Enter year:], [Enter month number:]+1, 1)

Entering 2009 for the year and 5 for the month will get all records in May.

If the date is stored in some other datatype post back with more details and
perhaps an example.
 
J

John W. Vinson

That almost works. What this person really wants is to be able to see
everyone who had surgery during each month of all the years. So I want to
just put in the month but not the year. I tried deleting the "Enter year"
part of what you gave me and it won't accept it. Can you give me another one
that will just ask for the month?

Hm. They don't care what year, they just want a count summing all records for
August 1998, August 2007, August 2004...?

If so, put a calculated field in the query

SurgeryMonth: Month([datefield])

This will have a value 1 for January ... 12 for December. Put a criterion on
this field of [Enter month number:] and you should be ok.

Note that to see a grid with years down the side, months across the top, and
numbers of patients at the intersection, you could do a Crosstab query using
Year([datefield]) as the Row Header and Month([datefield]) as the Column
Header.
 

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