我有 3 个组合框:
- 公司 - cboCOMP - tblCOMPANY
- 类别 - cboCAT - tblCATEGORY
- 舰队编号 - cboFLT - tblFLEET_NO
然后通过 cboCOMP 使用 tblFLEET_SETUP 的行源对这些(1&2)进行排序(标准)选择了一个值。
基本上我希望组合框(1,2 和 3)在下拉列表中显示它们各自的完整选项列表,即使 cboCOMP 没有选择值但我希望组合框根据每个单独的组合框进行过滤因此。这可能,我将如何做到这一点?
一旦我选择了我想要过滤的值,我将单击运行报告,但每次我执行唯一的组合框时,都会在运行报告时给我一个错误,那就是我为 cboFLT 选择了一个值。如果我将 cboFLT 留空,但在其他 2 个组合框中输入一个值,则报告运行良好。这是我为此使用的 vba 代码……</p>
Private Sub btnRUN_Click()
Dim vcomp As String
Dim vcat As String
Dim vflt As String
Dim filter As String
If Me.cboCOMP.Value <> "" Then
vcomp = "'" & Me.cboCOMP.Value & "'"
' MsgBox vcomp
filter = "COMPANY =" & vcomp & ""
' MsgBox filter
End If
'NEW IF STATEMENT
If Me.cboCAT.Value <> "" Then
vcat = "'" & Me.cboCAT.Value & "'"
If filter <> "" Then
filter = filter & " and "
' MsgBox filter
End If
filter = filter & "CATEGORY =" & vcat & ""
' MsgBox filter
End If
'NEW IF STATEMENT
If Me.cboFLT.Value <> "" Then
vflt = "'" & Me.cboFLT.Value & "'"
If filter <> "" Then
filter = filter & " and "
' MsgBox filter
End If
filter = filter & "FLEET NO =" & vflt & ""
' MsgBox filter
End If
DoCmd.OpenReport "rptQuick_Fuel_Report", acViewPreview, , filter
DoCmd.Close acForm, "Quick Fuel Lookup", acSaveNo
End Sub
错误代码是“
运行时错误 '3705':查询表达式 'COMPANY = 'JB' 和 CATEGORY = 'SOAP' 和 FLEET NO = 'Q 16'' 中的语法错误(缺少运算符)。
当我单击调试时,代码中的错误行是:
DoCmd.OpenReport "rptQuick_Fuel_Report", acViewPreview, , filter