Dear All,
I am building a personnel/training database and all has been going well until...
I created a form with 8 comboboxes populated with field lists from 2 tables. These are to allow the user to choose which headings appear in their Report. I found a module online, edited the form and report names, and tried to run it but receive various error messages. The form is called CustomReport and the report is called rptCustom. Please help if you can...I am still very new to Access . Thank you, Nicole
Option Compare Database
Option Explicit
Sub CustomReport()
On Error GoTo Err_CustomReport
DoCmd.OpenReport "rptCustom", acDesign
SetReportControls Forms!CustomReport.Combo10.Value, _
Reports!rptCustom.lblField1, Reports!rptCustom.tbfield1
SetReportControls Forms!CustomReport.Combo13.Value, _
Reports!rptCustom.lblField2, Reports!rptCustom.tbfield2
SetReportControls Forms!CustomReport.Combo12.Value, _
Reports!rptCustom.lblField3, Reports!rptCustom.tbfield3
SetReportControls Forms!CustomReport.Combo15.Value, _
Reports!rptCustom.lblField4, Reports!rptCustom.tbfield4
DoCmd.Close acReport, "rptCustom", acSaveYes
DoCmd.OpenReport "rptCustom", acPreview
Exit_CustomReport:
Exit Sub
Err_CustomReport:
MsgBox Err.Description
Resume Exit_CustomReport
End Sub
Private Sub btnCancel_Click()
DoCmd.Close
End Sub
Sub SetReportControls(varFieldName As Variant, conLabel As Control, conTextBox As Control)
If IsNull(varFieldName) Then
conLabel.Caption = " "
conTextBox.ControlSource = ""
conLabel.Caption = varFieldName
conTextBox.ControlSource = varFieldName
End If
End Sub
I am building a personnel/training database and all has been going well until...
I created a form with 8 comboboxes populated with field lists from 2 tables. These are to allow the user to choose which headings appear in their Report. I found a module online, edited the form and report names, and tried to run it but receive various error messages. The form is called CustomReport and the report is called rptCustom. Please help if you can...I am still very new to Access . Thank you, Nicole
Option Compare Database
Option Explicit
Sub CustomReport()
On Error GoTo Err_CustomReport
DoCmd.OpenReport "rptCustom", acDesign
SetReportControls Forms!CustomReport.Combo10.Value, _
Reports!rptCustom.lblField1, Reports!rptCustom.tbfield1
SetReportControls Forms!CustomReport.Combo13.Value, _
Reports!rptCustom.lblField2, Reports!rptCustom.tbfield2
SetReportControls Forms!CustomReport.Combo12.Value, _
Reports!rptCustom.lblField3, Reports!rptCustom.tbfield3
SetReportControls Forms!CustomReport.Combo15.Value, _
Reports!rptCustom.lblField4, Reports!rptCustom.tbfield4
DoCmd.Close acReport, "rptCustom", acSaveYes
DoCmd.OpenReport "rptCustom", acPreview
Exit_CustomReport:
Exit Sub
Err_CustomReport:
MsgBox Err.Description
Resume Exit_CustomReport
End Sub
Private Sub btnCancel_Click()
DoCmd.Close
End Sub
Sub SetReportControls(varFieldName As Variant, conLabel As Control, conTextBox As Control)
If IsNull(varFieldName) Then
conLabel.Caption = " "
conTextBox.ControlSource = ""
conLabel.Caption = varFieldName
conTextBox.ControlSource = varFieldName
End If
End Sub