
Code to reset database startup options
In the startup form I put the following code in the form load event:
' Bulletproof the app
Call SetStartupProperties
' Let me in if "SecretPasswordKey" is passed as a cmd parameter
Call CheckCommandLine
This will call functions to 'lock or bulletproof' the app each time the
db starts. It will also check for a certain value passed as a command
line option. If it finds that value it will then set the db to allow
the 'Shift' key on startup. Remember that when you reset the startup
property in code it will not take effect until next time that you start
the db. So if you are locked out you will need to start the db twice
and hold the shift key down when starting to get to the database window
and prevent the startup code from executing.
To work on you production db - create a shortcut to the db and use the
command line cmd/ option to allow the shift key. Always start the
production db with the shortcut while holding the shift key down.
Shortcut example: C:\Bulletproof.mdb /cmd "SecretPasswordKey"
Just make sure you run the mde at least once to set the correct
startup options.
If you can't figure this out I'll post an example - but I gotta go now.
Hope this helps.
Here's the rest of the code:
Function CheckCommandLine()
' Comments : Check value returned by Command function.
On Error GoTo PROC_ERR
If Command = "SecretPasswordKey" Then
ChangeProperty "AllowBypassKey", dbBoolean, True
Else
Exit Function
End If
PROC_EXIT:
Exit Function
PROC_ERR:
MsgBox Err.Description
Resume PROC_EXIT
End Function
Sub SetStartupProperties()
' Comments : Call ChangeProperty() for all of out properties.
On Error GoTo PROC_ERR
ChangeProperty "StartupShowDBWindow", dbBoolean, False
ChangeProperty "AllowBuiltinToolbars", dbBoolean, False
ChangeProperty "AllowFullMenus", dbBoolean, False
ChangeProperty "AllowBreakIntoCode", dbBoolean, False
ChangeProperty "AllowSpecialKeys", dbBoolean, False
ChangeProperty "AllowBypassKey", dbBoolean, False
PROC_EXIT:
Exit Sub
PROC_ERR:
MsgBox Err.Description
Resume PROC_EXIT
End Sub
Function ChangeProperty(pstrPropName As String, pvarPropType As
Variant, _
pvarPropValue As Variant) As Integer
' Comments : Changes the startup properties
' assures that the user can't get in
Dim dbs As DAO.Database
Dim prp As DAO.Property
Const conPropNotFoundError = 3270
On Error GoTo Change_Err
' Set to the current app
Set dbs = CurrentDb
' Attempt to change the propertu
dbs.Properties(pstrPropName) = pvarPropValue
' Success
ChangeProperty = True
Change_Bye:
Exit Function
Change_Err:
If Err = conPropNotFoundError Then
'Property not found.
Set prp = dbs.CreateProperty(pstrPropName, _
pvarPropType, pvarPropValue)
dbs.Properties.Append prp
Resume Next
Else
' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
--
Posted via http://dbforums.com