根据值字段在MS Access中隐藏控件 [英] Hide Controls in MS Access Based on Value Field

查看:166
本文介绍了根据值字段在MS Access中隐藏控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在MS Access中隐藏一些控件.这个想法是链接表具有诸如OpenResponse或OptionBox之类的问题.给定此输入后,我想切换用户可以输入的输入类型.这是我所拥有的示例:

I am trying to hide some controls in a form in MS Access. The idea is that a linked table has a type of question such as OpenResponse or OptionBox. Given this input I want to switch the type of input the user can input. Here is a sample of what I have:

Private Sub QuestionType_AfterUpdate()

    Dim QType As String

    Set QType = Me.QuestionType.Value

    Select Case QType

        Case OpenResponse
            Forms("Survey").Controls(AnswerField).Visible = True
            Forms("Survey").Controls(OptionTitle).Visible = False
            Forms("Survey").Controls(OptionFrame).Visible = False
            Forms("Survey").Controls(Option69).Visible = False
            Forms("Survey").Controls(Option70).Visible = False
            Forms("Survey").Controls(Option71).Visible = False
            Forms("Survey").Controls(Option72).Visible = False
            Forms("Survey").Controls(Option73).Visible = False
            Forms("Survey").Controls(Option74).Visible = False
            Forms("Survey").Controls(Option75).Visible = False
            Forms("Survey").Controls(Option76).Visible = False
            Forms("Survey").Controls(Option77).Visible = False
            Forms("Survey").Controls(Option78).Visible = False

        Case OptionBox

            Forms("Survey").Controls(AnswerField).Visible = False
            Forms("Survey").Controls(OptionTitle).Visible = True
            Forms("Survey").Controls(OptionFrame).Visible = True
            Forms("Survey").Controls(Option69).Visible = True
            Forms("Survey").Controls(Option70).Visible = True
            Forms("Survey").Controls(Option71).Visible = True
            Forms("Survey").Controls(Option72).Visible = True
            Forms("Survey").Controls(Option73).Visible = True
            Forms("Survey").Controls(Option74).Visible = True
            Forms("Survey").Controls(Option75).Visible = True
            Forms("Survey").Controls(Option76).Visible = True
            Forms("Survey").Controls(Option77).Visible = True
            Forms("Survey").Controls(Option78).Visible = True

    End Select

End Sub

推荐答案

在这里,您并不是在想开箱即用".在这种环境中,在盒子里"思考可能会破坏您的一天.

You're not thinking "out of the box", here. In this type of environment, thinking "inside the box" can ruin your day.

这是何时使用表驱动方法的完美示例.这里的主要问题是;问题可以/是否会改变?可能的答案是,是的.在这种情况下,我会做这样的事情:

This is a perfect example of when to use a table-driven approach. The primary question here is; Can/Will the questions ever change? The probable answer is, Yes. In this case, I would do the something like this:

创建一个名为Questions的表.在该表中,列出问题(可能在备注"字段中,但可以使用文本"字段),问题类型,控件名称和值(真"或假").然后,您可以根据问题类型查询问题"表,并遍历结果数据集以设置控件的Visible属性.这样,您以后随时可以根据需要随时添加更多问题.实际上,您可能还添加了一个名为QuestionID的主键和一个称为Active的True/False字段,因此您可以返回并删除某些问题,而无需创建孤立的记录,而仅查询标记为Active的问题.

Create a table called Questions. In that table, list the questions (possibly in a Memo field, but a Text field may work), the question type, the control name and the value (True or False). Then, you can query the Questions table based on question type, and loop through the resulting dataset to set the Visible property of your controls. This way, you can always add more questions later if necessary. In fact, you might also add a Primary Key called QuestionID, and a True/False field called Active so you can go back and remove some of the questions without creating orphaned records, and query only questions marked as Active.

如果我误解了您的目的,请告诉我,我将尝试相应地修改答案.

If I'm misunderstanding your purpose, let me know and I'll try to edit my answer accordingly.

这篇关于根据值字段在MS Access中隐藏控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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