2011-10-07 59 views
1

我与一些代码玩网络,并试图在我的项目下列禁用默认访问丝带的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 

我设置一个旁路移键控代码在窗体上,但我没有将其设置为我打开应用程序时加载的第一个表单。有什么办法可以绕过这个并返回到我的应用程序?

回答

1

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

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,你会现在必须创建一个名为自动执行宏:

RunCode : RunMe() 

而这个宏导出到损坏的数据库。要非常小心,首先备份所有东西。