VBA:如何将整行logging集添加到表单列表中

我有Excel VBA代码在访问数据库上运行select查询并返回logging集。 连接工作正常。 当我得到logging集时,我可以很好地访问每一行中的每个字段。 这是我目前使用的:

Sub accessSelect(sql) Set rs = New ADODB.Recordset Call accessConnection With rs .Open sql, conn End With Do While Not rs.EOF 'rtvEditForm.rtvList is a list box. rtvEditForm.rtvList.AddItem rs(1) & " - " & rs(2) rs.MoveNext Loop End Sub 

我想能够把整个rs扔在rtvEditForm.rtvList而不必引用每个字段。 我已经尝试过rtvEditForm.rtvList.AddItem rs ,但这不起作用,因为我得到一个“types不匹配”的错误。

看起来很简单,但我无法弄清楚这一点。 我现在的代码怎么做?

不需要做任何循环。 列表框具有可以绑定到ADOlogging集的logging集属性。

 Dim cn As ADODB.Connection Dim rs As ADODB.Recordset Set cn = New ADODB.Connection Set cn = CurrentProject.Connection Set rs = New ADODB.Recordset With rs Set .ActiveConnection = cn .Source = sql .LockType = adLockOptimistic .CursorType = adOpenKeyset .Open End With Set Me.rtvList.Recordset = rs rtvList.ColumnCount = rs.Fields.Count