MS Access Listbox只显示一条记录,当它的记录集被设置为来自Sqlite的ADODB记录集



我试图用命令按钮单击MS Access表单上的ADODB记录集更新一个列表框到Sqlite数据库文件。
recordset RecordCount属性正确返回100条记录,但是当代码运行时,Listbox只显示记录集中的第一行/记录。
这个列表框有什么问题,我错过了什么?谢谢你的帮助。
代码如下:

Private Sub cdRefresh_Click()
Dim Cnn As Object, Rst As Object
Dim cnString As String, SqlStr As String

cnString = "DRIVER=SQLite3 ODBC Driver;Database=E:Sample DataSales1.db"
Set Cnn = VBA.CreateObject("ADODB.Connection")
SqlStr = "Select * From Sales Limit 100;"
Cnn.Open cnString
Set Rst = VBA.CreateObject("ADODB.Recordset")
With Rst
Set .ActiveConnection = Cnn
.Source = SqlStr
.LockType = 3 '' adLockOptimistic
.CursorType = 1 '' adOpenKeyset
.Open
End With
Debug.Print "records #"; Rst.RecordCount '' despite RecordCount>1 , the listbox only shows one record
With Me.List0
.RowSourceType = "Table/Query"
.ColumnCount = Rst.Fields.Count
.ColumnHeads = True
Set .Recordset = Rst
End With
Set Rst = Nothing
Set Cnn = Nothing

End Sub

感谢所有在这里评论和做出贡献的人。
我可以通过将此属性添加到ADODB的属性集来解决我的问题。

Rst.CursorLocation = 3 '' adUseClient  

CursorLocation的默认值是2 "adUseServer",主要由连接类型决定。

最新更新