MS Access启动属性

时间:2011-10-07 04:58:11

标签: ms-access

我在网上玩了一些代码,并在我的项目中尝试了以下功能来禁用默认访问功能区

Sub DisableStartupProperties()
    ChangeProperty "StartupShowDBWindow", dbBoolean, False 
    ChangeProperty "StartupShowStatusBar", dbBoolean, False 
    ChangeProperty "AllowBuiltinToolbars", dbBoolean, False 
    ChangeProperty "AllowFullMenus", dbBoolean, False 
    ChangeProperty "AllowBreakIntoCode", dbBoolean, False 
    ChangeProperty "AllowSpecialKeys", dbBoolean, False 
    ChangeProperty "AllowBypassKey", dbBoolean, False 
    ChangeProperty "AllowShortcutMenus", dbBoolean, False
End Sub

Function ChangeProperty(strPropName As String, _
    varPropType As Variant, varPropValue As Variant) As Integer
    Dim dbs As Database, prp As Property
    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
        Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)
        dbs.Properties.Append prp
        Resume Next
    Else
        ChangeProperty = False
        Resume Change_Bye
    End If
End Function

我在表单上设置了By Pass Shift键代码,但我没有将其设置为打开应用程序时加载的第一个表单。有什么办法可以绕过这个并返回我的申请表吗?

2 个答案:

答案 0 :(得分:1)

从上面我知道你已经禁用了换档键旁路。最好的办法是在运行这个危险的代码之前使用你创建的副本:)如果这是不可能的,这里有一些想法,首先,你需要代码来更改锁定数据库中的代码。

Dim apAccess As New Access.Application
Dim strCodeLine As String
Dim lngLine As Long

''Where "c:\docs\test.mdb" is your database
apAccess.OpenCurrentDatabase "c:\docs\test.mdb"

''Where module2 is the name of your module  
With apAccess.VBE.ActiveVBProject.VBComponents("Module2").CodeModule
    s = "ChangeProperty ""AllowBypassKey"", dbBoolean, False"

    lngLine = 1

    ''EITHER
    ''This is useful if the code runs on start-up, if not, see OR
    If .Find(s, lngLine, 1, -1, -1) Then
        .ReplaceLine lngLine, Replace(s, "False", "True")
    End If

    ''OR
    ''Assuming that "Call DisableStartupProperties" is in a module, not a form
    If .Find("DisableStartupProperties", lngLine, 1, -1, -1) Then
        s = "Function RunMe()" & vbCrLf & s & vbCrLf & "End Function"

        .InsertLines lngLine - 1, s
    End If
End With

如果您选择了OR,则现在必须创建一个名为Autoexec的宏:

RunCode : RunMe()

将该宏导出到损坏的数据库。要非常小心,先备份一切。

答案 1 :(得分:0)

不用担心,如果您已使用VBA代码锁定了数据库。 有一种简单的方法,只需复制数据库并将其粘贴到不受信任的位置。

访问权限将显示警告,请不要单击“启用”。

现在您可以关闭表单,启用导航面板并取消隐藏对象。

一旦您将代码保存文件更改到受信任的位置。

希望你能理解我。