Code to reset database startup options 
Author Message
 Code to reset database startup options

Hi,

I have a couple database apps that I deploy as .mde files. My normal
procedure is: open .mdb, create .mde, close .mdb, open .mde, go to Tools,
Startup, uncheck all startup options except Display Status Bar.

This is ok as long as I **remember** to close .mdb, open .mde. Yesterday I
shutdown the startup options on the .mdb file by mistake. Fortunately I had
just made a backup, and restored that.

Is there a way I can use VBA code to create the .mde, then connect to it and
reset the .mde startup options without actually having to open it? If so, I
could just put the code in the .mdb file to create and reset .mde.

TIA,

Mark Vanderslice



Wed, 19 Oct 2005 03:56:42 GMT  
 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



Wed, 19 Oct 2005 08:47:31 GMT  
 Code to reset database startup options
Rockey,

Thanks, I'm pretty sure I can get what I need from that!

Mark V.

Quote:

> 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



Sat, 22 Oct 2005 03:12:22 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Open database without startup options?

2. Reset form size on startup?

3. VBA to reset Options

4. Reset Options in Outook 2000

5. Reset print options

6. VB Net Text Editor Options reset

7. reset Toggle btn in Option Grp when, Next Record

8. Urgent -Turn off Tools, Options, Edit/Find/Confirm on Startup

9. restore startup options

10. Setting startup options (Application Title etc) in DAO

11. Startup command-line options

12. loss of startup options

 

 
Powered by phpBB® Forum Software