如何过滤3个文本框,然后在MS Access VBA中根据它们运行报告



我有3个组合框:

  1. 公司-cboCOMP-tblCOMPANY
  2. 类别-cboCAT-tblCATEGORY
  3. 航班号-cboFLT-tblFLEET_NO

然后通过cboCOMP对这些(1&2(进行排序(标准(,行源为tblFLEET_SETUP我已经设置了每个组合框,以便它们相互过滤,但我只想知道如何根据cboCOMP做到这一点,只要它选择了一个值。

基本上,我希望组合框(1,2&3(在下拉菜单中显示其单独的完整选项列表,即使cboCOMP没有选择值,但我希望组合盒根据每个单独的组合框进行相应的过滤。这是可能的,我该怎么做?

一旦我选择了要筛选的值,我就会单击"运行报告",但每次我这样做时,唯一会在运行报告时出现错误的组合框是我为cboFLT选择了一个值。如果我将cboFLT留空,但在其他2个组合框中输入一个值,则报告运行良好。这是我正在使用的vba代码…

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='Q16英寸。

单击调试时,代码中的错误行为:
DoCmd.OpenReport "rptQuick_Fuel_Report", acViewPreview, , filter

字段FLEET NO有一个空格。带有空格或标点符号/特殊字符的对象名称必须包含在[]:[FEET NO]中。建议不要在命名约定中使用这些功能6月7日昨天

最新更新