Query Union Criteria (1 Viewer)

raphael99

Registered User.
Local time
Today, 05:27
Joined
Apr 6, 2015
Messages
126
Hi
I have a query Union based on two simple queries.
I have to set a command button on a form which print previous month entries of all records based on ID.
My question is:
1) should I have to set previous month criteria on each query for to have union query to work?
2) I have set on one query the following previous month criteria but it does not run:
Code:
Year([DataPIP])* 12 + DatePart("m", [DataPIP]) = Year(Date())* 12 + DatePart("m", Date()) - 1
 

plog

Banishment Pending
Local time
Today, 07:27
Joined
May 11, 2011
Messages
11,643
1. Yes, but...
2. Not a question.

...My advice is to create another query based on the UNION and apply the criteria there. That way you only have to do it in one place.

I don't know what you are trying to do with that criteria, but when you want previous month's data, its best to use DateAdd (http://www.techonthenet.com/access/functions/date/dateadd.php) in some way so that it works when you move from December to January.
 

raphael99

Registered User.
Local time
Today, 05:27
Joined
Apr 6, 2015
Messages
126
I have to set two different criteria:
1) to display all records in the query on the current month
2) to display all records in the query on previous month.
I don't know what to write

For previous month I found microsoft advice to use:
Code:
Year([DataPip])* 12 + DatePart("m", [DataPip]) = Year(Date())* 12 + DatePart("m", Date()) - 1
But it does not works
 

MSAccessRookie

AWF VIP
Local time
Today, 08:27
Joined
May 2, 2008
Messages
3,428
Hi

I get it working.
Thanks

And we have another satisfied customer! Please feel free to let us know the details of your solution if you have time to do so. It is helpful to know the final solutions of issues presented in the Forum, since other individuals with similar issues can often benefit from your experiences.

-- Rookie
 

raphael99

Registered User.
Local time
Today, 05:27
Joined
Apr 6, 2015
Messages
126
I got it working using for previous month the contidion:
Code:
WHERE (((Year([DataPIP])*12+DatePart("m",[DataPIP]))=Year(Date())*12+DatePart("m",Date())-1))

For current month instead I used:
Code:
WHERE Year([DataPip]) = Year(Now()) And Month([DataPiP]) = Month(Now())

Hope this help.
Thanks to all
 

Users who are viewing this thread

Top Bottom