Adam.Furtado
Registered User.
- Local time
- Today, 08:31
- Joined
- Feb 6, 2015
- Messages
- 17
Custom Report Fields based on Combo Boxes
Hello,
I am trying to create a customizable report that would allow the users to choose fields. I have a pretty common code that I found online and adapted it, but it fails on the first SetReportControl function.
The error reads: Run-time error 2465: Application-defined or object-defined error
Could it be something as simple as an incorrect reference? I have checked multiple times, but I am stumped.
This is a trial run, in the end I need to be able to open a report, then adjust the Report controls within 1 or more subreports inside the main report. That is a battle for another day.
Any assistance would be greatly appreciated.
Hello,
I am trying to create a customizable report that would allow the users to choose fields. I have a pretty common code that I found online and adapted it, but it fails on the first SetReportControl function.
The error reads: Run-time error 2465: Application-defined or object-defined error
Could it be something as simple as an incorrect reference? I have checked multiple times, but I am stumped.
Code:
Option Compare Database
Option Explicit
Sub MakeReport()
'On Error GoTo Err_MakeReport
'Open report in design view to write properties to objects
DoCmd.OpenReport "rptProductListIndTest", acDesign
'Read combo box selections and use subroutine to set report object properties
[COLOR="Red"] SetReportControls Forms!frmCustomReport.cboCurrentPrice.Value, Reports!rptProductListIndTest.lblCurrentPrice, Reports!rptProductListIndTest.txtCurrentPrice[/COLOR]
SetReportControls Forms!frmCustomReport.cboHistory1.Value, Reports!rptProductListIndTest.lblHistory1, Reports!rptProductListIndTest.txtHistory1
SetReportControls Forms!frmCustomReport.cboHistory2.Value, Reports!rptProductListIndTest.lblHistory2, Reports!rptProductListIndTest.txtHistory2
SetReportControls Forms!frmCustomReport.cboHistory3.Value, Reports!rptProductListIndTest.lblHistory3, Reports!rptProductListIndTest.txtHistory3
'Close design view without prompting to save changes
DoCmd.Close acReport, "rptProductListIndTest", acSaveYes
'Open finished report in preview view
DoCmd.OpenReport "rptProductListIndTest", acPreview
Exit_MakeReport:
Exit Sub
Err_MakeReport:
MsgBox Err.Description
Resume Exit_MakeReport
End Sub
Sub SetReportControls(varFieldName As Variant, conLabel As Control, conTextBox As Control)
'Check if selection is 'null'
If IsNull(varFieldName) Then 'Blank out the relevant objects
conLabel.Caption = " "
conTextBox.ControlSource = ""
Else 'Write the selected field name to the appropriate objects
conLabel.Caption = varFieldName
conTextBox.ControlSource = varFieldName
End If
End Sub
This is a trial run, in the end I need to be able to open a report, then adjust the Report controls within 1 or more subreports inside the main report. That is a battle for another day.
Any assistance would be greatly appreciated.