I am trying to do a report based on a crosstab query. SInce the column names aren’t known prior to formatting, I found code (courtesty of Getz, Litwin and Gilbert in Access 2000 Developers Handbook) which will produce a report based on a crosstab query…until Parameters enter into the process.
Below is my crosstab query SQL.
PARAMETERS [Start Date] DateTime, [End Date] DateTime;
TRANSFORM Count(tblVolunteerSchedule.VolDate) AS CountOfVolDate
SELECT tblVolunteers.LastName, tblVolunteers.FirstName
FROM tblVolunteers LEFT JOIN tblVolunteerSchedule ON tblVolunteers.VolunteerID = tblVolunteerSchedule.VolunteerID
WHERE (((tblVolunteerSchedule.VolDate) Between [Start Date] And [End Date]))
GROUP BY tblVolunteers.LastName, tblVolunteers.FirstName
PIVOT tblVolunteerSchedule.VolDate;
The crosstab query runs fine.
The report works fine if there are no parameters. But as soon as parameters are part of the report source, the report shows completely blank.
Below is the code for the report…
Private Sub Report_Open(Cancel As Integer)
Dim intColCount As Integer
Dim intControlCount As Integer
Dim i As Integer
Dim strName As String
On Error Resume Next
Dim rst As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
Set rst = db.OpenRecordset(“Query1”)
intColCount = rst.Fields.Count
intControlCount = Me.Detail.Controls.Count
If intControlCount < intColCount Then
intColCount = intControlCount
End If
For i = 1 To intColCount
strName = rst.Fields(i – 1).Name
Me.Controls("lblHeader" & i).Caption = strName
Me.Controls("txtData" & i).ControlSource = strName
Next i
For i = intColCount + 1 To intControlCount
Me.Controls("txtData" & i).Visible = False
Me.Controls("lblHeader" & i).Visible = False
Next i
rst.Close
End Sub
I know that crosstab reports are pesky at best, but I have worked at this for so long that I don't know which way to turn to make it come out right.
Why does the introduction of a parameter make the report go flooey? Is there a way to fix it?
Tom