Duane,
Thank you for the help so far. I hope that you will respond to this as
well. I found an older post from you that actually came up with a
different, and I think better (for me) solution. Here is the text of
that post, and I will follow with a few questions:
I do a lot of work with crosstabs and reporting from them. I generally
want
a crosstab to return a specific number of months' data for instance 3
months
or 6 or 12... To get these results, I use "relative" months so users
can
enter an ending date and my crosstab will display 6 months ending in
the
month entered.
The ending date would be a text box on a form Forms!frmA!txtEndDate
The columns in the crosstab are built using the expression
ColHead: "Mth" & DateDiff("m",[YourDateField],Forms!frmA!txtEndDate)
Set the Column Headings property to:
"Mth5","Mth4",..."Mth0"
The Mth0 column will be the month of the date entered in the text box.
Mth5
would be 5 months earlier.
When using a parameter in a crosstab query, you must select
Query|Parameters
and enter the
Forms!frmA!txtEndDate Date/Time
When using this query in a report, you can use text boxes for column
labels.
The control sources would be:
=DateAdd("m", -0, Forms!frmA!txtEndDate)
=DateAdd("m", -1, Forms!frmA!txtEndDate)
=DateAdd("m", -2, Forms!frmA!txtEndDate)
...
=DateAdd("m", -5, Forms!frmA!txtEndDate)
I got this working, and it shows the rolling months based on the end
date. Brilliant. The query works great. However, I used the report
wizard to create the initial report based on the query. When I open
the report, it pops up a text box asking for a value for tMain.ID.
tMain is my only table (where everything is stored) and obviously ID is
the autogenerated primary key field. I don't use this field anywhere
in either the query or the report. Any idea why it is asking for this
value, and how I can get it to stop?
Also, based on this solution, the column headings in the report show
the entire date (1/31/2006, 12/31/2005, etc). Is there a way to get
them to just display the month and year?
Thanks!
Tim