组合框的部分值 [英] Partial value from combo box

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

问题描述

我有一个组合框,它绑定到第1列和表中的ID#。根据组合框中的值,我想启用或禁用其他字段。问题是,我有许多相似的值,如多族/ Walkup,多族/四元,多族/双工等。目前,我有两个值的代码,但我不是想要一个很长的if语句,如果添加更多类型的Multi-Family /我不想硬编码id#'s。这是我在afterupdate事件中的当前代码。

I have a combo box that is bound to column 1 an ID# in a table. Based on the values in the combo box I would like to enable or disable other fields. The problem is, I have many values that are similar such as Multi-Family / Walkup, Multi-Family / Fourplex, Multi-Family /Duplex, etc. Currently, I have code that does this for two values but I don''t want a big long if statement and if more types of Multi-Family / are added I don''t want to hard code the id #''s. Here is my current code in the afterupdate event.

展开 | 选择 | Wrap | 行号

推荐答案

您的问题之前已从论坛,因为你提供的信息非常少。但是,当您希望具有与特定值相关联的条件时,要考虑的一种有用技术是将这些作为是/否字段包含在您需要时查找的参考表中,而不是对您的潜艇中的决策进行硬编码。在您添加或更改值时,将来更容易维护。


您的要求似乎基于属性类型,以文本形式存储(尽管您不是告诉我们源表的名称是什么或相关字段的名称。我建议您添加到源表,当前是您的组合的行源是/否字段,如EnableUnits,EnablePricePerUnit等。然后,您可以为表格中的每个单独行勾选或取消选中这些字段,以表示在选择该行的属性类型时要采取的操作。


在您的组合中然后将EnableUnits和EnablePricePerUnit字段添加到组合的行源,将相关列的宽度设置为0以隐藏它们。然后,您可以使用组合的Column属性来检索相关值并直接使用它来启用或禁用表单上的文本框。


假设您目前只有两列您的组合,如果您将EnableUnits字段添加为第三列,将EnablePricePerUnit字段添加为第四列,则您的sub将变为以下内容:

Your question was previously removed from the forum as you have supplied very little information to go on. However, one useful technique to consider when you want to have criteria associated with particular values is to include these as Yes/No fields in a reference table which you look up when required, rather than hard-coding the decisions in your subs. Makes it easier to maintain in the future as you add or change values, too.

Your requirements appear to be based on type of property, which is stored as text (though you don''t tell us what the name of the source table is or the name of the field concerned). I would suggest that you add to the source table that currently is the rowsource for your combo Yes/No fields such as EnableUnits, EnablePricePerUnit and so on. You would then tick or untick these fields for each separate row in the table to represent the action you want to take when that row''s property type is selected.

In your combo you would then add the EnableUnits and EnablePricePerUnit fields to the rowsource of the combo, setting the width of the columns concerned to 0 to hide them. You can then use the combo''s Column property to retrieve the relevant value and use it directly to enable or disable the textboxes on your form.

Assuming you currently have just two columns in your combo, if you add the EnableUnits field as the third column and the EnablePricePerUnit field as the fourth column your sub then just becomes the following:

展开 | 选择 | Wrap | 行号


感谢您的回复。我的表名是tblBuilding_Type_list,该字段是Building_Type_ID(自动编号)和Building_Type(文本)。你的假设是正确的,我会尝试这种技术。我从来没有尝试过这样的方式。


Chris
Thanks for your reply. My table name is tblBuilding_Type_list, the field are Building_Type_ID (Autonumber) and Building_Type (Text). Your assumptions are correct, I will try this technique. It never occurred to me to try it this way.

Chris


你是否仍然希望保持原来的方法,不要添加额外的字段/列,您可以使代码更高效:
Should you still wish to stay with your original approach, not add the extra Fields/Columns, you can make the Code a little more efficient:
展开 | 选择 | Wrap | 行号


这篇关于组合框的部分值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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