设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[模块/函数] 有关ADP禁止SHIFT键的方法

[复制链接]

点击这里给我发消息

跳转到指定楼层
1#
发表于 2003-3-29 17:06:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Function DisableBypassADP(blnYesNo As Boolean)
    CurrentProject.Properties.Add "AllowByPassKey", blnYesNo
End Function

然后在启动时调用 DisableBypassADP(false)

更详细的做法:

Function SetMyProperty(MyPropName As String, MyPropValue As Variant) As Boolean
    On Error GoTo SetMyProperty_In_Err
    Dim Ix As Integer
    With CurrentProject.Properties
    If fn_PropertyExist(MyPropName) Then  'check if it already exists
        For Ix = 0 To .Count - 1
            If .Item(Ix).Name = MyPropName Then
                .Item(Ix).Value = MyPropValue
            End If
        Next Ix
    Else
       .Add MyPropName, MyPropValue
    End If
    End With
    SetMyProperty = True

SetMyProperty_Exit:
    Exit Function

SetMyProperty_In_Err:
   
    MsgBox "设置属性出错:", Err, Error$
    SetMyProperty = False
    Resume SetMyProperty_Exit

End Function
'--------检查属性是否存在---
Private Function fn_PropertyExist(MyPropName As String) As Boolean
    fn_PropertyExist = False
    Dim Ix As Integer
    With CurrentProject.Properties
        For Ix = 0 To .Count - 1
            If .Item(Ix).Name = MyPropName Then
                fn_PropertyExist = True
                Exit For
            End If
        Next Ix
    End With
End Function


Public Function setByPass()
   SetMyProperty "AllowBypassKey", True
End Function


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享分享 分享淘帖 订阅订阅
2#
发表于 2003-3-29 21:30:00 | 只看该作者
好,收到。
3#
发表于 2003-3-30 00:16:00 | 只看该作者
AllowBypassKey 属性
请参阅 示例 特性使用 AllowBypassKey 属性可以指定是否允许用 Shift 键来忽略启动属性和 AutoExec 宏。例如,将 AllowBypassKey 属性设为 False 可避免用户忽略启动属性和 AutoExec 宏。

设置
AllowBypassKey 属性使用以下设置:

设置 说明
True 允许用户使用 Shift 忽略启动属性和 AutoExec 宏。
False 禁止用户使用 Shift 忽略启动属性和 AutoExec 宏。


可以使用宏或者 Visual Basic 设置该属性。

若要使用宏或 Visual Basic 设置 AllowBypassKey 属性,必须使用以下方法创建该属性:

在 Microsoft Access 数据库 (.mdb) 中,可以通过使用 CreateProperty 方法添加该属性,并将其追加到 Database 对象的 Properties 集合中。
注意这里:
在 Microsoft Access 项目 (.adp) 中,可以通过使用 Add 方法将该属性添加到 CurrentProject 对象的 AccessObjectProperties 集合中。

说明
调试应用程序时,应确保 AllowBypassKey 属性设为 True。

该属性的设置仅在下一次打开应用程序数据库时才会生效。

示例
下面的示例显示了一个名为 SetBypassProperty 的过程,该过程传递要设置的属性的名称、数据类型及所需设置。一般用途过程 ChangeProperty 将尝试设置 AllowBypassKey 属性,如果找不到该属性,则用 CreateProperty 方法将其追加到 Properties 集合中。这是必要的步骤,因为只有在添加之后,该属性才出现在 Properties 集合中。

Sub SetBypassProperty()
Const DB_Boolean As Long = 1
    ChangeProperty "AllowBypassKey", DB_Boolean, False
    '--------------如果需要解开shift锁定可以用以下代码:
    'ChangeProperty "AllowBypassKey", DB_Boolean, true

End Sub

Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
    Dim dbs As Object, prp As Variant
    Const conPropNotFoundError = 3270

    Set dbs = CurrentDb
    On Error GoTo Change_Err
    dbs.Properties(strPropName) = varPropValue
    ChangeProperty = True

Change_Bye:
    Exit Function

Change_Err:
    If Err = conPropNotFoundError Then    ' Property not found.
        Set prp = dbs.CreateProperty(strPropName, _
            varPropType, varPropValue)
        dbs.Properties.Append prp
        Resume Next
    Else
        ' Unknown error.
        ChangeProperty = False
        Resume Change_Bye
    End If
End Function

4#
发表于 2005-2-18 00:03:00 | 只看该作者
OK
5#
发表于 2021-10-15 19:04:57 | 只看该作者
很好
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-29 01:57 , Processed in 0.088537 second(s), 28 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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