Hi.
I have 2 combo boxes. One is a type select, and the select is a location select. There is also a open report button.
The 2nd combobox and the report button dynamically change based on the value of the first combobox. The dynamic rowsource works, but I am getting a syntax error with the open report command. Can anyone see what I need to change? I think my problem is my strField syntax. Here is the whole sub.
Private Sub OpenWattReport_Click()
On Error GoTo Err_OpenWattReport_Click
If Trim(Me!cboLocation & "") = "" Then
MsgBox "Please select a location.", vbOKOnly + vbInformation
Exit Sub
Else
Dim strReport As String 'Name of report to open.
Dim strField As String 'Record to generate report for
If Me!cboLocationType = "Signalized Intersection" Then
'Sets rowsource for cboLocation
Me!cboLocation.RowSource = "Intersection Data Query"
strReport = "rptWattReportwithDataNoType"
'Defines the location of the name used
strField = "[tblIntersectionWattage]![Intersection Name]"
Else
Me!cboLocation.RowSource = "qrySigns&FlashersNameFiltered"
'Sets rowsource for cboLocation
strReport = "rptWattReportSigns&Flashers"
'Defines the location of the name used
strField = "[tblSignWattage]![Location Name]"
End If
DoCmd.OpenReport strReport, acPreview, , "strField = & Me.cboLocation & " '"
End If
Exit_OpenWattReport_Click:
Exit Sub
Err_OpenWattReport_Click:
MsgBox Err.Description
Resume Exit_OpenWattReport_Click
End Sub
Thanks!
I have 2 combo boxes. One is a type select, and the select is a location select. There is also a open report button.
The 2nd combobox and the report button dynamically change based on the value of the first combobox. The dynamic rowsource works, but I am getting a syntax error with the open report command. Can anyone see what I need to change? I think my problem is my strField syntax. Here is the whole sub.
Private Sub OpenWattReport_Click()
On Error GoTo Err_OpenWattReport_Click
If Trim(Me!cboLocation & "") = "" Then
MsgBox "Please select a location.", vbOKOnly + vbInformation
Exit Sub
Else
Dim strReport As String 'Name of report to open.
Dim strField As String 'Record to generate report for
If Me!cboLocationType = "Signalized Intersection" Then
'Sets rowsource for cboLocation
Me!cboLocation.RowSource = "Intersection Data Query"
strReport = "rptWattReportwithDataNoType"
'Defines the location of the name used
strField = "[tblIntersectionWattage]![Intersection Name]"
Else
Me!cboLocation.RowSource = "qrySigns&FlashersNameFiltered"
'Sets rowsource for cboLocation
strReport = "rptWattReportSigns&Flashers"
'Defines the location of the name used
strField = "[tblSignWattage]![Location Name]"
End If
DoCmd.OpenReport strReport, acPreview, , "strField = & Me.cboLocation & " '"
End If
Exit_OpenWattReport_Click:
Exit Sub
Err_OpenWattReport_Click:
MsgBox Err.Description
Resume Exit_OpenWattReport_Click
End Sub
Thanks!