循环通过特定的组合框(数组) [英] Looping Through Specific Combo Boxes (Array)

查看:53
本文介绍了循环通过特定的组合框(数组)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要重新查询表单中要包含在数组中的特定组合框.组合框的顺序不正确,我不想遍历表单中的所有组合框.

I need to requery only specific combo boxes in a form, which I want to have in an array. The combo boxes are not in order and I do not want to loop through all combo boxes in the form.

我可以将其与之进行比较的最佳方法是在Excel中通过以下方法循环访问指定的工作表:

The best way I can compare it to is the following in Excel for looping through specified worksheets:

Dim ws As Worksheet
For Each ws In Worksheets("Sheet1", "Sheet4", "Sheet7")
    ' do something
Next ws

我无法弄清楚如何在Access中执行此操作.我尝试过这种变化:

I cannot figure out how to do this in Access. I have tried variations of this:

For Each Control In Me.Controls(Me.cbo1, Me.cbo4, Me.cbo7)
    Control.Requery
Next Control

推荐答案

对于轻量级方法,您可以将组合框名称放入逗号分隔的字符串中,然后将Split()字符串放入数组中,然后遍历数组成员.

For a lightweight approach, you can put the combo box names in a comma-separated string, Split() the string into an array, and then loop through the array members.

Const cstrNames As String = "cbo1,cbo4,cbo7"
Dim varName As Variant

For Each varName In Split(cstrNames, ",")
    Me.Controls(varName).Requery
Next

如果要在表单中的其他过程之间共享该列表,可以将字符串设为模块级常量,而不必在每个过程中再次声明.

If you want to share that list between other procedures in your form, you can make the string a module-level constant instead of declaring it again in each procedure.

这篇关于循环通过特定的组合框(数组)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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