A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Query Question



 
 
Thread Tools Display Modes
  #11  
Old June 10th, 2009, 09:34 PM posted to microsoft.public.access
KenSheridan via AccessMonster.com
external usenet poster
 
Posts: 1,610
Default Query Question

If Previous Date is intended to be the month/year prior to the current month
whenever the query is opened then you don't need a field for it at all as you
can compute it, so the query would be along these lines:

SELECT Account,
IIf(Max(Current) = Format(DateAdd("m",-1,Date()),"mm/yyyy"),"","")
AS NotBilled
FROM BillsReceived
GROUP BY Account;

where Account and Current are columns in a table BillsReceived.

This assumes that Current is a text field which stores the month and year
when the bill is received in the format mm/yyyy. This would present a
problem with bills received in different years however, e.g. a bill received
in December 2009 would have Current Value of '12/2009' whereas one received
in January 2010 would have a current value of '01/2010', but of these two
that for December would be returned as the 'later' bill by the Max operator
as the string '12/2009' sorts after the string '01/2010'.

You could get round this by returning a true date/time value of the first of
the month from the string

SELECT Account,
IIf(DateSerial(Right(Current,4),Left(Current,2),1)
= DateSerial(Year(Date()),Month(Date())-1,1) ,"","")
AS NotBilled
FROM BillsReceived
GROUP BY Account;

If on the other hand you were to store the date when each bill is recived in
a column date/time data type, DateReceived say, then you could use that to
return the first of the month:

SELECT Account,
IIf(DateSerial(Year(DateReceived),Month(DateReceiv ed),1)
= DateSerial(Year(Date()),Month(Date())-1,1) ,"","")
AS NotBilled
FROM BillsReceived
GROUP BY Account;

Ken Sheridan
Stafford, England

Jennie wrote:
Karl,

I tried to run the report with only this in the query:

Recent: IIf([Current][PreviousDate],"*","")

And I got an error message saying that the expression is not part of an
aggregate function. Did I enter it correctly? Thanks for your help.

The Max as you are using it will not give you the latest date as it is not
perfoming a function on a date. It is giving you the Max of the IIF function.

[quoted text clipped - 31 lines]
bill was received in 05/2009, I want the "" to appear. If they do match,
then I don't want anything to appear. What am I doing wrong?


--
Message posted via http://www.accessmonster.com

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:25 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.