如何从Access表单直接将数据加载到Excel Userform Listbox? [英] How to load data into Excel Userform Listbox from Access form directly?
问题描述
我想将Access中的一些数据加载到Excel Userform ListBox中.我现在正在做的是首先创建ADODB.Connection
来连接访问并创建ADODB.Recordset
来存储数据.其次,我使用Range("xx").CopyFromRecordset
将数据复制到Excel工作表.第三,将excel范围命名为"ResultSet
".第四,使用Me.ListName.RowSource="ResultSet"
将数据从excel工作表复制到ListBox.
I want to load some data from Access into Excel Userform ListBox. What I am doing now is creating ADODB.Connection
to connect access and create ADODB.Recordset
to store data, firstly. Secondly, I use Range("xx").CopyFromRecordset
to copy the data to excel sheet. Thirdly, name that excel range as "ResultSet
". Fourthly, use Me.ListName.RowSource="ResultSet"
to copy data from excel sheet to ListBox.
如您所见,我使用四个步骤来完成这项工作.是否可以跳过第2步和第3步,将数据直接从Access复制到ListBox?
As you can see, I use four steps to finish this job. Is there a way to skip step 2 and step 3, copying data from Access to ListBox directly?
谢谢
推荐答案
我找到了一篇文章.下面是代码,这是链接.
I found one article. Below is the code and this is the link.
With rs
.MoveLast
NoOfRecords = .RecordCount
.MoveFirst
End With
'Set the number of ListBox columns = number of fields in the recordset
ListBox1.ColumnCount = rs.Fields.Count
'Load the listbox with the retrieved records
ListBox1.Column = rs.GetRows(NoOfRecords)
谢谢
这篇关于如何从Access表单直接将数据加载到Excel Userform Listbox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!