【发布时间】:2015-03-08 18:08:11
【问题描述】:
我正在尝试使用多个组合框选择来过滤显示在最终组合框中的记录。如果我使用 Select Where 它工作正常,但只要我在语句中添加 AND,它就不会返回任何记录。我没有收到任何错误。只是没有结果,并已验证结果应该填充。目前,我已经删除了组合框变量 (me.combobox.value),并将值直接放入代码中以简化并尝试使其正常工作(例如通用电气和 Stage 1 Turbine Blade)。第一个代码集仅使用 WHERE 子句即可正常工作。第二个不起作用,因为我插入了一个 AND 子句。谁能告诉我为什么这不返回结果?
Private Sub cboConfiguration_AfterUpdate()
On Error Resume Next
Dim strSQL As String
Dim strComponent As String
Dim strOEM As String
Dim strScope As String
Dim strConfig As String
strScope = Me!cboScope.Value
strConfig = Me!cboConfiguration.Value
'this one will work
'strSQL = "SELECT * FROM MASTER_WORKSCOPES " & _
"WHERE OEM = " & " 'General Electric'"
'this one returns no results
'strSQL = "SELECT * FROM MASTER_WORKSCOPES " & _
"WHERE OEM = " & " 'General Electric' AND Components = " & " 'Stage 1 Turbine Blade'"
Me.cboTables.RowSourceType = "Table/Query"
Me.cboTables.RowSource = strSQL
Me.cboTables.Requery
Me.cboTables.Enabled = True
Me.cboTables.SetFocus
Me.cboTables.Dropdown
End Sub
【问题讨论】:
-
您说您已验证结果应该填充。这是否意味着您运行相同的 SQL 并返回记录?
-
当您将相同的
SELECT语句粘贴到新 Access 查询的 SQL 视图中并在那里运行时,Access 会找到多少条记录?SELECT * FROM MASTER_WORKSCOPES WHERE OEM = 'General Electric' AND Components = 'Stage 1 Turbine Blade'
标签: mysql ms-access combobox vba