我有一个列表框名称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
为什么直通查询不会填充列表框?