Can anyone help me out please? I have the following code that makes a report from comboboxes in a form, but I am unable to sort by the variable field. What do I need to add to this code to have it sort by "lblfield1"/"tbfield1" ? Thank you, Nicole
Private Sub Command54_Click()
On Error GoTo Err_MakeReport
DoCmd.OpenReport "rptCustom", acDesign
SetReportControls Forms!CustomReport.Combo43.Value, _
Reports!rptCustom.lblfield1, Reports!rptCustom.tbfield1
SetReportControls Forms!CustomReport.Combo44.Value, _
Reports!rptCustom.lblfield2, Reports!rptCustom.tbfield2
SetReportControls Forms!CustomReport.Combo46.Value, _
Reports!rptCustom.lblfield3, Reports!rptCustom.tbfield3
SetReportControls Forms!CustomReport.Combo45.Value, _
Reports!rptCustom.lblfield4, Reports!rptCustom.tbfield4
SetReportControls Forms!CustomReport.Combo40.Value, _
Reports!rptCustom.lblfield5, Reports!rptCustom.tbfield5
SetReportControls Forms!CustomReport.Combo42.Value, _
Reports!rptCustom.lblfield6, Reports!rptCustom.tbfield6
SetReportControls Forms!CustomReport.Combo41.Value, _
Reports!rptCustom.lblfield7, Reports!rptCustom.tbfield7
DoCmd.Close acReport, "rptCustom", acSaveYes
DoCmd.OpenReport "rptCustom", 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)
If IsNull(varFieldName) Then
conLabel.Caption = " "
conTextBox.ControlSource = ""
Else
conLabel.Caption = varFieldName
conTextBox.ControlSource = varFieldName
End If
End Sub
Private Sub btnCancel_Click()
DoCmd.Close
End Sub
Private Sub btnMakeReport_Click()
MakeReport
End Sub
Private Sub Command54_Click()
On Error GoTo Err_MakeReport
DoCmd.OpenReport "rptCustom", acDesign
SetReportControls Forms!CustomReport.Combo43.Value, _
Reports!rptCustom.lblfield1, Reports!rptCustom.tbfield1
SetReportControls Forms!CustomReport.Combo44.Value, _
Reports!rptCustom.lblfield2, Reports!rptCustom.tbfield2
SetReportControls Forms!CustomReport.Combo46.Value, _
Reports!rptCustom.lblfield3, Reports!rptCustom.tbfield3
SetReportControls Forms!CustomReport.Combo45.Value, _
Reports!rptCustom.lblfield4, Reports!rptCustom.tbfield4
SetReportControls Forms!CustomReport.Combo40.Value, _
Reports!rptCustom.lblfield5, Reports!rptCustom.tbfield5
SetReportControls Forms!CustomReport.Combo42.Value, _
Reports!rptCustom.lblfield6, Reports!rptCustom.tbfield6
SetReportControls Forms!CustomReport.Combo41.Value, _
Reports!rptCustom.lblfield7, Reports!rptCustom.tbfield7
DoCmd.Close acReport, "rptCustom", acSaveYes
DoCmd.OpenReport "rptCustom", 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)
If IsNull(varFieldName) Then
conLabel.Caption = " "
conTextBox.ControlSource = ""
Else
conLabel.Caption = varFieldName
conTextBox.ControlSource = varFieldName
End If
End Sub
Private Sub btnCancel_Click()
DoCmd.Close
End Sub
Private Sub btnMakeReport_Click()
MakeReport
End Sub