如何从Access表单直接将数据加载到Excel Userform Listbox? [英] How to load data into Excel Userform Listbox from Access form directly?

查看:145
本文介绍了如何从Access表单直接将数据加载到Excel Userform Listbox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆