Link to home
Create AccountLog in
Avatar of Paul Barrett
Paul BarrettFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Trigger code in Access db that is locked, to unlock it

I have made a bit of a development faux pas!
Prior to releasing my access 2007 db to the end users I always run code that locks it (no bypass key) and does some other stuff.
I went to site, unlocked the db (I have a hidden button on a welcome form that does this, but only available when user logs on and form presented).  I made some changes, relocked, put on my usb stick, bought back to my office, went to open it forgetting that there would be an ODBC error re different SQL instance.  Office is 50 miles away so would rather not go back just to get an unlocked one!

As I cannot open it I cannot get to the form that has hidden button to run unlock code.

Can I fire the code from outside that db so it will perform the code on that db?

Code:
Public Sub SetBypassProperty()
Const DB_Boolean As Long = 1
    Application.SetOption "ShowWindowsInTaskbar", False
    ChangeProperty "StartupShowDBWindow", DB_Boolean, False
    ChangeProperty "StartupShowStatusBar", DB_Boolean, False
    ChangeProperty "AllowBuiltinToolbars", DB_Boolean, False
    ChangeProperty "AllowFullMenus", DB_Boolean, False
    ChangeProperty "AllowBreakIntoCode", DB_Boolean, False
    ChangeProperty "AllowSpecialKeys", DB_Boolean, False
    ChangeProperty "AllowBypassKey", DB_Boolean, False
End Sub

Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
    Dim dbs As Object, prp As Variant
    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    ' Property not found.
        Set prp = dbs.CreateProperty(strPropName, _
            varPropType, varPropValue)
        dbs.Properties.Append prp
        Resume Next
    Else
        ' Unknown error.
        ChangeProperty = False
        Resume Change_Bye
    End If
End Function
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of Paul Barrett

ASKER

Thanks Peter, I have decided to split the points as Peter came first and it was his solution that I used.  Jim's solution explained how I could do this myself so I believe it warrants 100 of the points, hope this is OK