Steven,
The challenge of using a cross-tab as the column headers for a report is
that you cannot be sure what values will show up, unless you know exactly
what values are in that column, and force the query to return those values.
In your example data, you would have columns AA, AB, and AC, but what if the
last record for Sam wasn't there, then you would only have columns (AA and
AB). The way to force the Crosstab query to list specific columns, and to
put them in the order you want is with a IN clause, as Ken did in his
example. Access will normally alphabetized the column headers and will only
return columns for those values that are in the column identified as the
column header. However, the In clause allows you to:
1. Force the return of columns, even if there is no matching data in the
recordset, and
2. Put them in whatever order you want them in.
So, if you had sales data, and you wanted the column headers to be the month
number, then you might have a query that looks like:
TRANSFORM NZ(Sum(Sales), 0)
SELECT RegionID, OfficeID
FROM tbl_Sales
WHERE YEAR(SalesDate) = 2007
GROUP BY RegionID, OfficeID
PIVOT Month(SalesDate)
But if you wanted the month headers to be the three character abbreviation
for the month, you might use:
TRANSFORM NZ(Sum(Sales), 0)
SELECT RegionID, OfficeID
FROM tbl_Sales
WHERE YEAR(SalesDate) = 2007
GROUP BY RegionID, OfficeID
PIVOT Format(SalesDate, "mmm")
IN ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Oct", "Nov",
"Dec")
Note, the values in the IN clause must match exactly what is in the Pivot
column (although they are not case sensitive). If you look closely, I have
"accidentally" forgetten to put "Sep" in the list, and if you make this kind
of error, it would be obvious when the columns are months, but it may not be
obvious that you have left something out.
The other challenge with using Cross-tab queries as the source for a report,
is that depending on the query, you might not have the same column headers
from one month to another. In this case, you will have to create a dynamic
report that has some code behind it to set the names of the column headers
and set the control source of the various columns. If you need to do this,
do a Google search on:
Access +dynamic +crosstab +reports
HTH
Dale