Query by Month and Year (Repost)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I am reposting this question because I cannot access the original question
nor the reply.

I have a table with contribution information, with a date field for posting
the date of the contribution. I would like to query this information by
month and year.

I first used the following:

=[Start Date] And <=[End Date]

which works pretty well, but I would like to make it easier for the user so
the only have to input a month and year. So, I further refinded this by
using:

Between DateSerial(Year(Date()), [Enter month NUMBER (1-12)],1) AND
DateSerial(Year(Date()),1+ [Enter month NUMBER (1-12)],0)

That worked great, except it only gives me the current year. So if I enter
"12" I only get information for December 2008. After further investigation,
I found this code in another post here (I entered my own table and field
names). I added this code to the current code in SQL view, but keep getting
error (syntax)
messages when I try to save it

PARAMETERS TheYear Long, TheMonth Long;
SELECT tblReceipts.[ContributionDate]
FROM tlbReceipts
WHERE (([ContributionDate] >= DateSerial(TheYear, TheMonth, 1))
And ([ContributionDate] < DateSerial(TheYear, TheMonth + 1, 1)))

I've copied the text from the SQL view here. This is what the code looks
like now:

SELECT tblContributor.ContributorID,
tblContributor.[LastName/OrganizationName], tblContributor.FirstName,
tblReceipts.ContributionDate, tblReceipts.Amount
FROM tblContributor INNER JOIN tblReceipts ON tblContributor.ContributorID =
tblReceipts.ContributorID
WHERE (((tblReceipts.ContributionDate) Between
DateSerial(Year(Date()),[Enter month NUMBER (1-12)],1) And
DateSerial(Year(Date()),1+[Enter month NUMBER (1-12)],0)));

PARAMETERS TheYear Long, TheMonth Long;
SELECT tblReceipts.[ContributionDate]
FROM tlbReceipts
WHERE (([ContributionDate] >= DateSerial(TheYear, TheMonth, 1))
And ([ContributionDate] < DateSerial(TheYear, TheMonth + 1, 1)));

The error says: Syntax error (missing operator) in query expression
'(((tblReceipts.ContributionDate) Between DateSerial(Date()),[Enter month
NUMBER (1-12)],1) And DateSerial(Year(Date()),1+[Enter month NUMBER
(1-12)],0)))

I've tried deleting the first WHERE statement because I realize it's
redundant, but that doesn't work either.

In addition, will this solution work if I want to query by YEAR, so that I
get the information for a certain year (the whole year)?

Thanks!


.



Relevant Pages

  • Query By Month and Year - Access 2007
    ... I have a table with contribution information, with a date field for posting ... FROM tlbReceipts ... Syntax error in query expression ... In addition, will this solution work if I want to query by YEAR, so that I ...
    (microsoft.public.access.queries)
  • Re: SELECT vs. ORDER BY - order of execution question
    ... HI Cinnie - For your original question, the answer are both yes and no: ... a particular query on the assumption that there is a definite order between ... standard convention found in most VBA and SQL texts. ...
    (microsoft.public.access.queries)
  • Re: Query by Month and Year (Repost)
    ... I have a table with contribution information, with a date field for posting ... FROM tlbReceipts ... I've copied the text from the SQL view here. ... Syntax error in query expression ...
    (microsoft.public.access.queries)
  • Re: [PHP] Getting mysql_query results into an array
    ... and don't put them into an array at all. ... query is nasty and the PHP is fast and easy, ... The original question was "what's most efficient". ... even though they appear in the original order within the raw ...
    (php.general)
  • Re: Problems with JTabbedPane
    ... with a number of JPanels placed on a JPanel in a JFrame, but the entire display is just empty. ... You don't even seem to have read my original question. ... SSCCE is a way, the best way, to post a query with the needed information to be helped. ...
    (comp.lang.java.gui)