Query criteria is a month

Egg 'n' Bacon
5StarLounger
Posts: 736
Joined: 18 Mar 2010, 11:05

Query criteria is a month

Post by Egg 'n' Bacon »

Been some time since I've done any real Access work and it's scary how much I've forgotten.

Anyway, want a simple query that returns results for a specific month (via combo box on separate form, format = dd/mm/yyyy, with the first of the month).
Records can have any 'day' number, but must be included.

What's the simplest method / syntax please?

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Query criteria is a month

Post by HansV »

One way to do it:

Add two calculated columns to the query design grid:

Y: Year([DateField])

and

M: Month([DateField])

where DateField is the name of the date field you want to filter on.
Clear the Show check box for these columns.
Set the Criteria row for the Y column to

Year([Forms]![NameOfForm]![NameOfComboBox])

and that for the M column to

Month([Forms]![NameOfForm]![NameOfComboBox])

substituting the name of the form and combo box, of course.
Best wishes,
Hans

Egg 'n' Bacon
5StarLounger
Posts: 736
Joined: 18 Mar 2010, 11:05

Re: Query criteria is a month

Post by Egg 'n' Bacon »

So simple.

Will give it a go in a bit

Cheers

Egg 'n' Bacon
5StarLounger
Posts: 736
Joined: 18 Mar 2010, 11:05

Re: Query criteria is a month

Post by Egg 'n' Bacon »

Works great.

I did miss out that this is a 'totals' query and needs to be grouped / summed.
Where there are multiple records in the month, I still get separate unique results.

Would I need to do a secondary 'totals' query to achieve this?

User avatar
HansV
Administrator
Posts: 78629
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Query criteria is a month

Post by HansV »

Do not include the date field itself in the query!
Best wishes,
Hans

Egg 'n' Bacon
5StarLounger
Posts: 736
Joined: 18 Mar 2010, 11:05

Re: Query criteria is a month

Post by Egg 'n' Bacon »

Doh!

Thank you