禁用旁路键

disabling the bypass key

我想在 autoexec 期间在打开表单事件中禁用我的数据库的旁路密钥,以便用户无法查看我的表单的基础表。我找到了以下代码,并在自动执行期间打开表单时创建了一个 运行 模块。该模块称为 SetBypass

Call SetBypass

Option Compare Database

Public Function SetByPass(rbFlag As Boolean, File_name As String) As Integer
    DoCmd.Hourglass True
    On Error GoTo SetByPass_Error
    Dim db As Database
    Set db = DBEngine(0).OpenDatabase(File_name)
    db.Properties!AllowBypassKey = rbFlag
setByPass_Exit:
    MsgBox "Changed the bypass key to " & rbFlag & " for database " &     File_name, vbInformation, "Skyline Shared"
    db.Close
    Set db = Nothing
    DoCmd.Hourglass False
    Exit Function


SetByPass_Error:
    DoCmd.Hourglass False
    If Err = 3270 Then
        ' allowbypasskey property does not exist
        db.Pro  perties.Append db.CreateProperty("AllowBypassKey", dbBoolean, rbFlag)

        Resume Next
    Else
        ' some other error message
        MsgBox "Unexpected error: " & Error$ & " (" & Err & ")"
        Resume setByPass_Exit
    End If
End Function  

上述模块需要在应用程序外部调用 如果您在同一数据库中,请尝试以下代码

Sub blockBypass()
Dim db As Database, pty As DAO.Property
Set db = CurrentDb
  On Error GoTo Constants_Err 'Set error handler
  db.Properties("Allowbypasskey") = False
  db.Close

Constants_X:
    Exit Sub

Constants_Err:
    If Err = 3270 Then 'Bypass property doesn't exist

        'Add the bypass property to the database
        Set pty = db.CreateProperty("AllowBypassKey", dbBoolean _
            , APP_BYPASS)
        db.Properties.Append pty
        Resume Next

    End If
    MsgBox Err & " : " & Error, vbOKOnly + vbExclamation _
        , "Error loading database settings"

End Sub