GetOption, SetOption Methods Example

The following example uses the GetOption method to return the Default Field Type option setting from the Tables/Queries tab of the Options dialog box and then saves the setting in a variable. If the Default Field Type option isn't currently set to Text, Microsoft Access displays a dialog box asking the user whether it should set the option to Text. If the user clicks Yes, the SetOption method changes the option.

Sub ChangeFieldSize()
    ' Constant represents Text setting of Default
    ' Field Type option.
    Const conText = 0

    Dim varSize As Variant, intResponse As Integer
    Dim strMsg As String

    ' Determine current setting.
    varSize = Application.GetOption("Default Field Type")
    strMsg = "Set default field type to Text?"
    If varSize <> conText Then
    ' Prompt user to change setting if it's not Text.
        If MsgBox(strMsg, vbYesNo) = vbYes Then
            ' Change setting to Text.
            Application.SetOption "Default Field Type", conText
        End If
    End If
End Sub