Startup Properties Example

The following example shows a procedure named SetStartupProperties that passes the name of the property to be set, its data type, and its desired setting. The general purpose procedure ChangeProperty attempts to set the startup property and, if the property isn't found, uses the CreateProperty method to append it to the Properties collection. This is necessary because these properties don't appear in the Properties collection until they've been set or changed at least once.

Sub SetStartupProperties()
Const DB_Text As Long = 10
Const DB_Boolean As Long = 1
    ChangeProperty "StartupForm", DB_Text, "Customers"
    ChangeProperty "StartupShowDBWindow", DB_Boolean, False
    ChangeProperty "StartupShowStatusBar", DB_Boolean, False
    ChangeProperty "AllowBuiltinToolbars", DB_Boolean, False
    ChangeProperty "AllowFullMenus", DB_Boolean, True
    ChangeProperty "AllowBreakIntoCode", DB_Boolean, False
    ChangeProperty "AllowSpecialKeys", DB_Boolean, True
    ChangeProperty "AllowBypassKey", DB_Boolean, True
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