设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[模块/函数] 一个根据名称类批量操作的函数

[复制链接]
跳转到指定楼层
1#
发表于 2008-5-6 15:55:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Function hy_CtlBatProByName(frmForm As Form, strCtlLeftName As String, strOperName As String, Optional varOperValue As Variant)
'===============================================================================
'功能描述:根据控件最左边的字符批量执行操作
'参数说明:strOperName为操作参数,参数很多,具体参考下面的CASE语句
'使用示例:把所有以txtQ开始的控件(不一定是文本控件,只是一种命名策略而已)清空,hy_CtlBatProByName Me.Form, "txtQ", "Value", Null;又如移出所有标签的冒号;hy_CtlBatProByName Me.Form, "Label", "RemoveColon", true
'创建日期:2008-06-16  更新日期: 2008-06-16
'测试状态:OK
'===============================================================================
On Error Resume Next
Application.Echo False
Dim ctl As Control
For Each ctl In frmForm.Controls
    If Left(ctl.Name, Len(strCtlLeftName)) Like strCtlLeftName Then
        If strOperName = "Visible" Then '控件是否可见
            ctl.Visible = varOperValue
        ElseIf strOperName = "Enabled" Then '控件是否可用
            ctl.Enabled = varOperValue
        ElseIf strOperName = "Value" Then '批量设置控件值
            If TypeOf ctl Is TextBox Or TypeOf ctl Is ListBox Or TypeOf ctl Is ComboBox Or TypeOf ctl Is CheckBox Then
                ctl.Value = varOperValue
            End If
        ElseIf strOperName = "LimitToList" Then '限制到列表(组合框和列表框有效)
            If TypeOf ctl Is ListBox Or TypeOf ctl Is ComboBox Then
                ctl.LimitToList = varOperValue
            End If
        ElseIf strOperName = "Caption" Then '批量这是标题,如果操作值为空字符则清空所有
            If TypeOf ctl Is Label Then
                If Nz(varOperValue, "") = "" Then
                    ctl.Caption = ""
                End If
            End If
        ElseIf strOperName = "RemoveColon" Then '移出或增加标签控件的冒号,此时不用指定操作值true(移出)或false(增加)
            If ctl.Section = acDetail And (TypeOf ctl Is Label) Then
                If Right(ctl.Caption, 1) = ":" Or Right(ctl.Caption, 1) = ":" Then
                    If varOperValue = True Then ctl.Caption = Left(ctl.Caption, Len(ctl.Caption) - 1)
                Else
                    If varOperValue = False Then ctl.Caption = ctl.Caption & ":"
                End If
            End If
        Else
            MsgBox hy_LanguageMsgItem("1212"), , hy_LanguageMsgItem("1203")
            Exit Function
        End If
    End If
Next ctl
Application.Echo True
End Function
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享分享 分享淘帖 订阅订阅
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-21 21:34 , Processed in 0.105659 second(s), 24 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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