Im trying to build a cross-tab report with dynamic column headings. I've download various examples and am trying to import the code from a report in an example database into my own report. I've named the textbox controls for all column headings and detail rows to match that of the example.
The report errors out at line below with 'Object doesn't support this property or method' but it works in the example... What am I doing wrong. Do textboxes have captions? I tried setting this to value instead but that didnt work either.
Me("txtHeading" & intX).Caption = rst(intX).Name
The report errors out at line below with 'Object doesn't support this property or method' but it works in the example... What am I doing wrong. Do textboxes have captions? I tried setting this to value instead but that didnt work either.
Me("txtHeading" & intX).Caption = rst(intX).Name
Code:
Private Sub Report_Open(Cancel As Integer)
Const conNumColumns = 11
Dim qdf As DAO.QueryDef
Dim rst As DAO.Recordset
Dim intColumnCount As Integer
Dim intX As Integer
On Error GoTo Handle_Err
' Set record source.
RecordSource = "qryRAirlineFuelMTD2_Crosstab"
' Open QueryDef object.
Set qdf = CurrentDb.QueryDefs("qryRAirlineFuelMTD2_Crosstab")
' Set query parameters based on values in form.
qdf.Parameters("Forms![frmReportBuildAirlineFuelUseMTD]!txtStartDate") = Forms![frmReportBuildAirlineFuelUseMTD]!txtStartDate
qdf.Parameters("Forms![frmReportBuildAirlineFuelUseMTD]!txtEndDate") = Forms![frmReportBuildAirlineFuelUseMTD]!txtEndDate
' Open recordset.
Set rst = qdf.OpenRecordset
' Don't open report if there are no data.
If rst.RecordCount = 0 Then
MsgBox "No records found.", vbInformation
Cancel = True
GoTo Handle_Exit
End If
' Fix number of columns in crosstab query and limit to max available.
intColumnCount = rst.Fields.Count - 1
If intColumnCount >= conNumColumns Then
intColumnCount = conNumColumns - 1
End If
For intX = 1 To intColumnCount
' Set caption of label in page header to field name.
Me("txtHeading" & intX).Caption = rst(intX).Name
Next intX
' Set control source of first text box in detail section to row header.
Me("txtColumn1").ControlSource = "=[" & rst(1).Name & "]"
' Start totals in column 2 (the first column with a crosstab value).
For intX = 2 To intColumnCount
' Set control source of text box in detail section to fraction of column total; replace nulls by 0.
Me("txtColumn" & intX).ControlSource = "=Nz([" & rst(intX).Name & "],0)/Sum([" & rst(intX).Name & "])"
Next intX
DoCmd.Maximize
Handle_Exit:
On Error Resume Next
rst.Close
Set rst = Nothing
Set qdf = Nothing
Exit Sub
Handle_Err:
MsgBox Err.Description, vbExclamation
Resume Handle_Exit
End Sub