开发者

MS Access Start up Properties

开发者 https://www.devze.com 2023-04-11 14:27 出处:网络
I was playing with some code online and tried the following in my project to disable default access ribbon

I was playing with some code online and tried the following in my project to disable default access ribbon

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", dbBoo开发者_JAVA百科lean, 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

I set a By Pass Shift Key Code on a form but i hadn't set it as the first form to load when i opened the application. is there any way i can bypass this and return to my application?


From the above I understand that you have disabled the shift-key bypass. The best thing to do would be to use the copy you created before running this dangerous code :) If that is not possible, here are some ideas, first, you will need code to change the code in the locked database.

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

If you have chosen OR, you will now have to create a macro called Autoexec:

RunCode : RunMe()

And export that macro to your damaged database. Be very careful, back-up everything first.


Don’t worry, If you have locked your database by using VBA codes. There is a simple way, just copy your database and paste somewhere in not trusted location.

Access will show you a warning don’t click “enable”.

Now you can close form, enable navigation panel and unhide objects.

Once you change the code save file on trusted location.

Hope you can understand me.

0

精彩评论

暂无评论...
验证码 换一张
取 消