根据VBA中的另一个选择重置一个字段 [英] Reset a field based on selection of another in VBA

查看:140
本文介绍了根据VBA中的另一个选择重置一个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VBA中有一个名为 cbo_deptCode 的下拉字段。我想要另外一组名为 cbo_moduleCode cbo_moduleName 的字段在每次用户从下拉列表中选择时清除任何当前条目 cbo_deptCode 。组合框是窗体控件。如何实现这一点?

I have a drop down field in VBA called cbo_deptCode. I would like another set of fields called cbo_moduleCode and cbo_moduleName to be cleared of any current entry each time the user makes a selection from the drop down cbo_deptCode. The combo boxes are form controls. How can I go about achieving this?

推荐答案

将宏分配给cbo_deptCode。

Assign a macro to cbo_deptCode.

在宏中有如下代码:

Sub cbo_deptCode_Change()
    'Update selected index for combo boxes to 0 I.E. no selection
    ActiveSheet.Shapes("cbo_moduleCode").OLEFormat.Object.Value = 0
    ActiveSheet.Shapes("cbo_moduleName").OLEFormat.Object.Value = 0
End Sub

如果cbo_moduleCode和cbo_moduleName与cbo_deptCode不在同一个工作表中,则需要指定工作表而不是调用ActiveSheet。另外,如果这些不是实际的控制名,这将失败。

If cbo_moduleCode and cbo_moduleName are not on the same sheet as cbo_deptCode, you'll need to specify the sheet instead of calling the ActiveSheet. Also, this will fail if those aren't the actual control names.

编辑:
如果您实际使用Active- X控件(虽然你说你使用表单控件),格式更简单:
Sheet。[controlname] .value = IE ActiveSheet.cbo_moduleCode.Value =
或更复杂的方法(不推荐)涉及形状:

If you are actually using Active-X controls (though you said you were using form controls), the format is simpler: Sheet.[controlname].value = "" I.E ActiveSheet.cbo_moduleCode.Value = "" Or the more convoluted method (not recommended) that involves Shapes:

ActiveSheet.Shapes(cbo_moduleCode)。OLEFormat.Object.Object.Value =

这篇关于根据VBA中的另一个选择重置一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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