【发布时间】:2016-08-05 18:52:55
【问题描述】:
我有一个列表框名称animal,并且行源设置为以下代码,其中查询“animal”是直通查询。但是,列表框不会填充任何动物。注意:如果我将查询“动物”作为独立的通过查询运行,它会正确运行,它只是不会填充列表框。单击列表框时,几乎就像没有执行查询一样。
Private Sub animallist_Enter()
Dim Q As QueryDef
Dim DB As Database
' Use for dynamic SQL statement'
Dim strSQL As String
' Modify the Query.
Set DB = CurrentDb()
Set Q = DB.QueryDefs("animal")
strSQL = "Select distinct(animal) From AnimalDB.Animaltable"
Q.SQL = strSQL
Q.Close
Me.animal.RowSource = strSQL
End Sub
如果我通过 ODBC 连接到“AnimalDB.Animaltable”并运行以下代码(将查询切换为选择而不是通过),列表框将填充动物。
Private Sub animallist_Enter()
Dim Q As QueryDef
Dim DB As Database
' Use for dynamic SQL statement'
Dim strSQL As String
' Modify the Query.
Set DB = CurrentDb()
Set Q = DB.QueryDefs("animal")
strSQL = "Select distinct(animal) From [AnimalDB_Animaltable]"
Q.SQL = strSQL
Q.Close
Me.animal.RowSource = strSQL
End Sub
为什么直通查询不会填充列表框?
【问题讨论】:
标签: sql vba ms-access listbox pass-through