2011-10-07 75 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() 

而這個宏導出到損壞的數據庫。要非常小心,首先備份所有東西。