使用 VBA 循环组合框列表并为每个组合框运行 MS Access 宏

发布于 2024-10-27 23:38:28 字数 456 浏览 3 评论 0原文

目前我有一个 MS Access 2003 表单,其中包含名称组合框列表。使用此工具的方法:从下拉列表中选择一个名称,然后单击 MS Access 宏,该宏根据所选名称运行(3 个不同的查询),然后打开一个主 Excel 模板并运行一个 Excel 宏,该宏将创建 1每个销售人员的个人档案。

我想做的事情:使用 MS Access VBA 代码循环组合框中的姓名列表,然后运行现有的 MS Access 宏来单独运行姓名列表中的每个查询,然后将每个销售人员数据导出到excel 模板已格式化或只是一个 Excel 文件,我将格式化。

我不想手动选择每个名称,从下拉列表中总共有 300 多个名称,运行所有这些查询需要很长时间。我想使用 VBA 代码循环遍历表单上组合框中的每个名称,并使用每个名称运行现有的 ms access 宏(一起运行 3 个查询),然后我想让该函数将每个单独的文件导出到 Excel 。最终结果是每个销售人员都会有自己的 Excel 文件。

Currently I have an MS Access 2003 form with a combo box list of names. The way to use this tool: You select a name from the drop down and then click the MS Access Macro which runs (3 different queries) based upon name selected and then you open a master Excel Template and run an Excel Macro which will create 1 individual file for each salesperson.

What I am trying to do: Use MS Access VBA code to loop though the list of names in the combo box and then run the existing MS Access Macro to run each query from the list of names indiividually and then export each sales persons data to an excel Template which is already formatted or just to an Excel file and I will format.

I dont want to manually select a each name, a total of over 300 names from the drop down, it takes too long to run all of these queries. I want to use VBA code to loop through each name in the combo box on the form and use each name to run the existing ms access macro (which runs 3 queries together) and then I want to have the function export each individual file to Excel. The end result is that each salesperson will have his own Excel file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你没皮卡萌 2024-11-03 23:38:28
Dim i As Long
  with myCombo
    For i = 0 To .ListCount
        Debug.Print .ItemData(i)
    Next i
end with
Dim i As Long
  with myCombo
    For i = 0 To .ListCount
        Debug.Print .ItemData(i)
    Next i
end with
肩上的翅膀 2024-11-03 23:38:28

虽然 iDevlop 的答案在技术上是正确的,但它也会在最后给出组合框的 Null 值。因此,如果您只想列出不为空的项目,请使用

Dim i As Long
With combobox
   For i = 0 To .ListCount - 1
       Debug.print .ItemData(i)
   Next i
End With

Although the answer of iDevlop is technically correct, it would also give the Null value of the combobox at the end. So if you just want the listed items without null, use

Dim i As Long
With combobox
   For i = 0 To .ListCount - 1
       Debug.print .ItemData(i)
   Next i
End With
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文