T
Tim Long
Hello, can you please tell me what I'm doing wrong here?
I have a textbox (txtMonthYear) on a form (frmReports). The textbox has no
format, but has an input mask 00/0000
I want to run a variety of queries/reports off the value the user enters in
txtMonthYear. So when the user enters 01/2008 I want to run a report, for
example, on the data from January 2008.
Testing how I could do this, I ran the following query. It works fine:
SELECT tblClients.Client_ID, tblClients.d_received, Format([d_received],
"mmyyyy") AS MonthYear
FROM tblClients
WHERE Format([d_received], "mmyyyy") = [Forms]![frmReports].[txtMonthYear]
This gives me the data for January, no problem. Trying to test for the data
for the month prior to that, I ran the following query:
SELECT tblClients.Client_ID, tblClients.d_received, Format([d_received],
"mmyyyy") AS MonthYear
FROM tblClients
WHERE Format([d_received], "mmyyyy") = Format(DateAdd("M",
-1,[Forms]![frmReports].[txtMonthYear]), "mmyyyy")
This returned nothing.. no error message, just no data (but there is plenty
of data for that month).
If I run the following, however, it works fine (returns last month's data):
SELECT tblClients.Client_ID, tblClients.d_received, Format([d_received],
"mmyyyy") AS MonthYear
FROM tblClients
WHERE Format([d_received], "mmyyyy") = Format(DateAdd("M", -1,Date(),"mmyyyy")
I've checked that txtMonthYear doesn't have the focus (tabbed out of it to
make sure) when I ran the above queries.
Eventually I want to run 12-month reports off the user-provided month/year,
so when the user enters 01/2008, a report can be generated for the twelve
months to that month (Feb 2007 tio Jan 2008 inclusive). I am planning on
using DateAdd and "M", -12 to give me the 12 months worth of data but can't
get it working. It's driving me up the wall!
Any help would be much appreciated.
Many thanks
Tim Long
I have a textbox (txtMonthYear) on a form (frmReports). The textbox has no
format, but has an input mask 00/0000
I want to run a variety of queries/reports off the value the user enters in
txtMonthYear. So when the user enters 01/2008 I want to run a report, for
example, on the data from January 2008.
Testing how I could do this, I ran the following query. It works fine:
SELECT tblClients.Client_ID, tblClients.d_received, Format([d_received],
"mmyyyy") AS MonthYear
FROM tblClients
WHERE Format([d_received], "mmyyyy") = [Forms]![frmReports].[txtMonthYear]
This gives me the data for January, no problem. Trying to test for the data
for the month prior to that, I ran the following query:
SELECT tblClients.Client_ID, tblClients.d_received, Format([d_received],
"mmyyyy") AS MonthYear
FROM tblClients
WHERE Format([d_received], "mmyyyy") = Format(DateAdd("M",
-1,[Forms]![frmReports].[txtMonthYear]), "mmyyyy")
This returned nothing.. no error message, just no data (but there is plenty
of data for that month).
If I run the following, however, it works fine (returns last month's data):
SELECT tblClients.Client_ID, tblClients.d_received, Format([d_received],
"mmyyyy") AS MonthYear
FROM tblClients
WHERE Format([d_received], "mmyyyy") = Format(DateAdd("M", -1,Date(),"mmyyyy")
I've checked that txtMonthYear doesn't have the focus (tabbed out of it to
make sure) when I ran the above queries.
Eventually I want to run 12-month reports off the user-provided month/year,
so when the user enters 01/2008, a report can be generated for the twelve
months to that month (Feb 2007 tio Jan 2008 inclusive). I am planning on
using DateAdd and "M", -12 to give me the 12 months worth of data but can't
get it working. It's driving me up the wall!
Any help would be much appreciated.
Many thanks
Tim Long