Setting Startup Options Programmatically in Microsoft Access

(Updated 2010-09-27)

[ Main | AccessTips ]


The MS recommended code at Setting Startup Options Programmatically in Access 2000 However that code doesn't easily handle setting multiple properties.  That page though does have all the startup option property names.  

The code that I use is as follows.  I don't know where I originally found the code in the first place.  As I occasionally get easily confused I put this code in my mdlAutoExec module.  This module also has all the code used to do initializing, open forms, check the backend is correct and valid, etc, etc.

Sub SetNewFEMDBOptions()
Dim intX As Integer

    intX = AddAppProperty("AppTitle", dbText, "Sample Application Title")
    intX = AddAppProperty("StartUpMenuBar", dbText, "Sample Startup Menu Bar")
    intX = AddAppProperty("StartUpForm", dbText, "Sample Start Up Form")
    intX = AddAppProperty("StartUpShowDBWindow", dbBoolean, False)

    MsgBox "Now Exit and go back in to test."

End Sub

Function AddAppProperty(strName As String, varType As Variant, _
        varValue As Variant) As Integer
    Dim prp As Property
    Const conPropNotFoundError = 3270

    On Error GoTo AddProp_Err
    CurrentDb.Properties(strName) = varValue

    AddAppProperty = True

    Exit Function

    If Err = conPropNotFoundError Then
        Set prp = CurrentDb.CreateProperty(strName, varType, varValue)
        CurrentDb.Properties.Append prp
        AddAppProperty = False
        Resume AddProp_Bye
    End If
End Function


Here's the code with which you can loop through the properties collection to view your current settings.  Note that there are a lot of settings you really don't need to worry about.  The three in my sample code above are likely the most important ones.

Sub ViewAppProperties()

On Error GoTo tagError
Dim prp As Property, i As Integer
Dim strPropName As String, varPropValue As Variant, varPropType As Variant
Dim varPropInherited As Variant, intPropPropCount As Integer
Dim strError As String

With CurrentDb

    For i = 0 To (.Properties.Count - 1)
        strPropName = .Properties(i).Name
        varPropValue = Null
        varPropValue = .Properties(i).Value
        varPropType = .Properties(i).Type
        varPropInherited = .Properties(i).Inherited
        Debug.Print strPropName & ": " & varPropValue & ", " & _
            varPropType & ", " & varPropInherited & ";" & strError
        strError = ""
    Next i

End With
Exit Sub

    Select Case Err.Number
    Case 3251
        strError = Err.Number & "," & Err.Description
        Resume Next
    Case Else
        MsgBox Err.Description
    Exit Sub
    End Select
End Sub

[ Access Tips | Access | Main ]

Auto FE Updater   Auto FE Updater distribute new and updated Front End databases to your users with several mouse clicks.

Wrench and gear Granite Fleet Manager - the best designed fleet maintenance tracking and management system available

Comments email Tony  Search Contact Tony's Blog Privacy Policy Table of Contents

Website copyright 1995-2013 Tony Toews