设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 5592|回复: 8
打印 上一主题 下一主题

Use the "Tag" Property of a Form or Report Control to manage Form

[复制链接]

点击这里给我发消息

跳转到指定楼层
1#
发表于 2005-8-15 19:32:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
标题:Use the "Tag" Property of a Form or Report Control to manage Form or Report functionality.

原作者:ATTAC Consulting Group

原文网址:http://ourworld.compuserve.com/homepages/attac-cg/AFormTip.htm#KEY

摘抄人:tmtony

翻译人:



The "Tag" property of a form or report control is not used by Access directly, and can be used by the programmer to manage how a form or report functions in many ways. As an example, you may have a Form which under certain circumstances you want to show one set of multiple fields and under other circumstances show another set of multiple fields. You could write an event procedure to hide or show the controls, similar to the following list, in the After Update event of an option group: If Opt=1 then

        Me!Control1.visible=True

        Me!Control2.visible=True

        Me!Control3.visible=False

        Me!Control4.visible=False

        etc.

Else

        Me!Contol1.visible=False

        Me!Control2.visible=True

        Me!Control3.visible=False

        Me!Control4.visible=False

        etc.

End If

The former type of code requires you to change the code if you add more controls to those you want to hide or show. Alternately you could type in either "Opt1" or "Opt2" to the "Tag" property of each control you want to change whether to hide or show according to the option by the user. Then you could write your code, entering it to the "After Update" event of an Option Group, to loop through the controls on the form and make the changes to the identified controls automatically. The code might look like this: Dim Frm as Form

Dim I as integer

Set Frm = Me



If Opt=1 then

    For I = 0 to Frm.count -1

       If Instr(Frm( I ).tag, "Opt1")>0 then Frm( I ).visible = True

       If Instr(Frm( I ).tag, "Opt2")>0 then Frm( I ).visible = False

    Next I

Else

    For I = 0 to Frm.count -1

        If Instr(Frm( I ).tag, "Opt1")>0 then Frm( I ).visible = False

        If Instr(Frm( I ).tag, "Opt2")>0 then Frm( I ).visible = True

   Next I

End If

This later set of code also allows you to add or delete controls from the those that are visible or hidden without changing your code, simply by adding one of the options to a controls "Tag" property. (Note, we check whether the Tag property has "Opt1" or "Opt2" in the string contained in the Tag property rather than checking whether the Tag is equal to either "Opt1" or "Opt2" because we may place more than one action tags in the Tag property of the same control.)
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2005-8-15 21:10:00 | 只看该作者
水平有限,不过也来译一下,还请各位帮助指正

我对原文的些不理解的地方,自己进行了替换,如第一段 multiple fields,我看一下讲的是控件,就把他充成 控件集了

译文

---------------------------------------------------------------------

标题:使用Tag属性来组织窗体或报表的事件过程窗体或报表控件的“Tag”(标记)属性不能被Aceess直接使用,但可以让编程人员能以多种方法去组织一个窗体或报表的事件过程。例如,你可能想定制一个窗体的控件集在某种情况下为一种显示方式,在另一种情况下为另一种显示方式。你可以在一个选项组的更新后事件中写一个事件过程去隐藏或显示这些控件,类似于允许显示。









If Opt=1 then

        Me!Control1.visible=True

        Me!Control2.visible=True

        Me!Control3.visible=False

        Me!Control4.visible=False

        ......

Else

        Me!Contol1.visible=False

        Me!Control2.visible=True

        Me!Control3.visible=False

        Me!Control4.visible=False

        ......

End If







这种形式的代码当你想隐藏或显示更多的控件时,需要及时的去修改。你可以分别在需要隐藏或显示的每一个控件的Tag属性中写入 "Opt1" 或 "Opt2"。这样你可以在一个选项组的更新后事件中写入你的代码,通过历遍窗体每一个控件的Tag属性,从而自动的进行改变。这样的代码看起来类似下面:







Dim Frm as Form







Dim I as integer

Set Frm = Me



If Opt=1 then

    For I = 0 to Frm.count -1

       If Instr(Frm( I ).tag, "Opt1")>0 then Frm( I ).visible = True

       If Instr(Frm( I ).tag, "Opt2")>0 then Frm( I ).visible = False

    Next I

Else

    For I = 0 to Frm.count -1

        If Instr(Frm( I ).tag, "Opt1")>0 then Frm( I ).visible = False

        If Instr(Frm( I ).tag, "Opt2")>0 then Frm( I ).visible = True

   Next I

End If







这样的代码允许你稍后添加或删除那些需要显示或隐藏处理的控件,而不需要修改代码,只需在这些控件的Tag属性中写入或删除判断字符就可以了。(提示:我们通过查找Tag属性中是否含有"Opt1" 或 "Opt2"字符串的方式来进行判断而不是通过检测Tag属性等于"Opt1" 或 "Opt2"的方式判断,是因为我们有可能在这些控件的Tag属性中放置更多的判断字符)











[此贴子已经被作者于2005-8-15 19:32:53编辑过]

3#
发表于 2005-8-16 03:27:00 | 只看该作者
只要是跟access有关的,我看没什么能难倒我们的狸。。。呵。呵。[em01][em01][em01]
4#
发表于 2006-6-1 00:17:00 | 只看该作者
只要是跟access有关的,我看没什么能难倒我们的狸
5#
发表于 2006-6-1 00:17:00 | 只看该作者
只要是跟access有关的,我看没什么能难倒我们的狸
6#
发表于 2006-6-1 00:18:00 | 只看该作者
只要是跟access有关的,我看没什么能难倒我们的狸
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-2 23:22 , Processed in 0.100015 second(s), 29 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表