如何从Access表单直接将数据加载到Excel Userform Listbox?

编程入门 行业动态 更新时间:2024-10-28 18:36:33
本文介绍了如何从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?

本文发布于:2023-10-30 22:01:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1544129.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   加载   数据   Access   Userform

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!