Report based on Crosstab Query

  • Thread starter Thread starter Doreen
  • Start date Start date
D

Doreen

I am trying to create a report that is based on a crosstab
query that is based on a date range.
What the problem is - is that when the query changes - so
do the column headings - when the report is then generated
and goes into error because the headings have changed.

Any thoughts on how I can generate this?
 
Try not to use "absolute" column headings for dates. You could possibly use
"relative" dates. For instance if your column headings were months:
Form: frmA
Text Box: txtEndDate
Table: tblSales
Field: SaleDate
You want to show 12 months of sales in columns of a crosstab report.
Set the Query|Parameters
Forms!frmA!txtEndDate Date/Time

Use this expression for your Column Headings:
ColHead:"Mth" & DateDiff("m",[SaleDate],Forms!frmA!txtEndDate)
This will produce Mth0, Mth1, Mth2, Mth3,... where Mth0 is sales from the
same month as the ending date on your form.
Mth1 is the previous month etc.

Set your queries Column Headings property to:
Mth0, Mth1, Mth2, Mth3,.., Mth11

Build your report based on these "relative" months. If you need column
labels in your report, use text boxes:
=DateAdd("m",0,Forms!frmA!txtEndDate)
=DateAdd("m",-1,Forms!frmA!txtEndDate)
=DateAdd("m",-2,Forms!frmA!txtEndDate)
=DateAdd("m",-3,Forms!frmA!txtEndDate)
....
This solution requires no code and will run fairly quickly.
 
Back
Top