如何绕过Access数据库中的AllowBypassKey限制?
绕过Access数据库的AllowByPassKey限制并修改数据库
我接手了一个Access数据库需要修改,但打开后仅弹出一个表单,其余内容全被隐藏。数据库配置了AllowByPassKey宏,按住Shift键打开也无法绕过限制。我已经将数据库导入新Access库查看了VBA代码,找到了控制Shift键的函数,但仍不知道如何突破限制完成修改。
找到的VBA代码如下:
Function ap_DisableShift() 'This function disable the shift at startup. This action causes 'the Autoexec macro and Startup properties to always be executed. On Error GoTo errDisableShift Dim db As DAO.Database Dim prop As DAO.Property Const conPropNotFound = 3270 Set db = CurrentDb() 'This next line disables the shift key on startup. db.Properties("AllowByPassKey") = False 'The function is successful. Exit Function errDisableShift: 'The first part of this error routine creates the "AllowByPassKey 'property if it does not exist. If Err = conPropNotFound Then Set prop = db.CreateProperty("AllowByPassKey", _ dbBoolean, False) db.Properties.Append prop Resume Next Else MsgBox "Function 'ap_DisableShift' did not complete successfully." Exit Function End If End Function Function ap_EnableShift() 'This function enables the SHIFT key at startup. This action causes 'the Autoexec macro and the Startup properties to be bypassed 'if the user holds down the SHIFT key when the user opens the database. On Error GoTo errEnableShift Dim db As DAO.Database Dim prop As DAO.Property Const conPropNotFound = 3270 Set db = CurrentDb() 'This next line of code disables the SHIFT key on startup. db.Properties("AllowByPassKey") = True 'function successful Exit Function errEnableShift: 'The first part of this error routine creates the "AllowByPassKey 'property if it does not exist. If Err = conPropNotFound Then Set prop = db.CreateProperty("AllowByPassKey", _ dbBoolean, True) db.Properties.Append prop Resume Next Else MsgBox "Function 'ap_DisableShift' did not complete successfully." Exit Function End If End Function
解决方法
方法1:执行现有ap_EnableShift函数
既然已经能看到这个启用Shift键的函数,直接执行它即可:
- 打开导入后的新数据库,按
Alt + F11打开VBA编辑器 - 按
Ctrl + G调出即时窗口 - 在窗口中输入
?ap_EnableShift并回车,执行该函数 - 保存数据库,用这个修改后的文件覆盖原数据库,之后按住Shift键打开原文件就能绕过限制
方法2:直接修改AllowByPassKey属性
如果执行函数报错,可直接在即时窗口操作数据库属性:
- 打开VBA编辑器的即时窗口,先尝试输入:
CurrentDb.Properties("AllowByPassKey") = True - 若提示属性不存在,执行以下代码创建并设置属性:
Dim prop As DAO.Property Set prop = CurrentDb.CreateProperty("AllowByPassKey", dbBoolean, True) CurrentDb.Properties.Append prop - 保存后关闭,替换原数据库文件,即可用Shift键正常打开
方法3:创建临时宏执行启用函数
如果前两种方法都不生效,可通过临时宏实现:
- 新建空白Access数据库,将原数据库的VBA模块导入到这个空白库中
- 创建一个宏,添加
RunCode操作,选择ap_EnableShift()作为执行的函数 - 运行该宏,保存空白库后用它替换原数据库,再按住Shift键打开即可
内容的提问来源于stack exchange,提问作者Robino7254
相关产品推荐
相关产品推荐

