常有网友问起关于如何不显示数据库窗口与重新显示数据库窗口的问题,其实这些问题ACCESS的帮助中都有,整理如下:
-----------------------------------------------------------------------------------

AllowBypassKey 属性

使用 AllowBypassKey 属性可指定是否允许使用 Shift 键来忽略启动属性和 AutoExec 宏。例如,将 AllowBypassKey 属性设为 False 可避免用户忽略启动属性和 AutoExec 宏。

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

设置 说明
True (-1) 允许用户使用 Shift 键忽略启动属性和 AutoExec 宏。
False (0) 不允许用户使用 Shift 键忽略启动属性和 AutoExec 宏。

可以使用宏或 Visual Basic 对该属性进行设置。
要使用宏或 Visual Basic 设置 AllowBypassKey 属性,必须使用以下方法创建该属性:
在 Microsoft Access 数据库 (.mdb) 中,可以通过使用 CreateProperty 方法添加该属性并将该属性追加到 Database 对象的 Properties 集合中。
在 Microsoft Access 项目 (.adp) 中,可以通过使用 Add 方法将属性添加到 CurrentProject 对象的 AccessObjectProperties 集合中。

说明
在调试应用程序时应确保 AllowBypassKey 属性设置为 True 。
该属性的设置只有在应用程序数据库下一次打开时才会生效。

AllowBypassKey 属性示例

下列示例显示了一个名为 SetBypassProperty 的过程,该过程传递了要设置的属性的名称、数据类型以及想进行的设置。通用目标过程 ChangeProperty 试图设置 AllowBypassKey 属性,而且如果没有找到该属性,就使用 CreateProperty 方法将该属性添加到 Properties 集合。这是必要的,因为只有在添加之后,该属性才出现在 Properties 集合中。

Sub SetBypassProperty()
Const DB_Boolean As Long = 1
   ChangeProperty "AllowBypassKey", DB_Boolean, False
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

' 有关ADP禁止SHIFT键的方法
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

 

0 回复,0 引用: 设置是否充许使用SHIFT安全键打开数据库

添加回复

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。