如何根据组合框的值禁用控件? [英] How to disable controls based on value of a combo box?

查看:75
本文介绍了如何根据组合框的值禁用控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据zmbd,我已经开始了一个新线程并在这里引用了这个帖子:https://bytes.com/topic/access/answers/964884-if-statement-form-data-entry-property


如果cboEquipmentStatus的值为2,则尝试使某些cbo和txt框被禁用(和/或锁定),如果其值为1则启用。或者在Storage /中操作。


我创建了一个函数,我在Form_Current中调用该函数以及cboEquipmentStatus_OnChange。


这是我的代码:

Per zmbd, I''ve started a new thread and am referencing this thread here: https://bytes.com/topic/access/answers/964884-if-statement-form-data-entry-property

I''m trying to make certain cbo and txt boxes be disabled (and/or locked) if cboEquipmentStatus''s Value is 2 and enabled if its value is 1. Or In Storage / Operational.

I have created a function and I''m calling that function in Form_Current as well as cboEquipmentStatus_OnChange.

Here is my code:

展开 | 选择 | Wrap | 行号

推荐答案

首先,我建议使用after_update事件。将控件设置为禁用以在设计时开始,然后根据需要在after_update中启用。这样,如果用户更改某些内容并且所有内容都有效,则应启用正确的控件。
On first thought, I would suggest using the after_update event. Set your controls to disabled to start with at design time and then enable as needed in the after_update. This way, if the user changes something and everything validates then the correct controls should be enabled.


cboEquipmentStatus的AfterUpdate事件(如上所述)和Form的Current事件是所需的事件。


cboEquipmentStatus_AfterUpdate事件由用户更改组合的值触发。表单加载时以及用户在记录中导航时触发表单'的当前事件。


我认为OnChange事件的问题是只有控件的TEXT属性有在那一点发生了变化。在控件更新(更新事件之前和之后)之前,VALUE属性(您正在测试)不会更改。此外,Change事件将触发您在控件中键入的每个字符,而After Update事件仅在您在该字段中完成数据输入后触发一次。
cboEquipmentStatus''s AfterUpdate event (as mentioned above) and The Form''s Current event are the needed events for this.

The cboEquipmentStatus_AfterUpdate event gets triggered by the user changing the combo''s value. The form''s Current Event fires when the form loads and as the user navigates through records.

I believe the problem with the OnChange event is that only the TEXT property of the control has changed at that point. The VALUE property (which you are testing) does not change until the control has updated (before and after update events). Additionally, the Change event fires with each character you type in the control, versus the After Update event which fires only once after you have completed your data entry in that field.


感谢您的帮助! AfterUpdate和Form_Current工作了!

Thanks for your help! AfterUpdate and Form_Current worked!

附加图像
newequipmentform2.jpg (60.8 KB,1769次观看次数)
Attached Images
newequipmentform2.jpg (60.8 KB, 1769 views)


这篇关于如何根据组合框的值禁用控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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