应用程序 SetOption 方法 (Access)Application.SetOption method (Access)

SetOption 方法设置 Access 选项对话框中的选项的当前值。The SetOption method sets the current value of an option in the Access Options dialog box.

语法Syntax

表达式SetOption(OptionName,设置)expression.SetOption (OptionName, Setting)

expression:表示 Application 对象的变量。expression A variable that represents an Application object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
OptionNameOptionName 必需Required StringString 选项的名称。The name of the option. 有关选项名称参数字符串的列表, 请参阅Set options From Visual BasicFor a list of option name argument strings, see Set options from Visual Basic.
SettingSetting 必需Required VariantVariant 与该选项设置相对应的值。A value corresponding to the option setting. setting 参数的值取决于特定选项的可能设置。The value of the setting argument depends on the possible settings for a particular option.

备注Remarks

可用的选项设置取决于要设置的选项的类型。The available option settings depend on the type of option being set. 有三种常规类型的选项:There are three general types of options:

  • 可以通过选中或清除复选框进行设置的“是/否”选项。Yes/No options that can be set by selecting or clearing a check box.

  • 可以通过输入一个字符串或数值进行设置的选项。Options that can be set by entering a string or numeric value.

  • 可以从列表框、组合框或选项组中进行选择的预定义选项。Predefined options that can be chosen from a list box, combo box, or option group.

对于用户通过选中或清除复选框来设置的选项 (使用SetOption方法), 请为 setting 参数指定TrueFalse , 如下面的示例所示。For options that the user sets by selecting or clearing a check box, using the SetOption method, specify True or False for the setting argument, as in the following example.

Application.SetOption "Show Status Bar", True

若要使用SetOption方法设置选项类型, 请指定将在对话框中键入的字符串或数值。To set a type of option by using the SetOption method, specify the string or numeric value that would be typed in the dialog box. 下面的示例将默认表单模板设置为 OrderTemplate。The following example sets the default form template to OrderTemplate.

Application.SetOption "Form Template", "OrderTemplate"

为其设置列表框或组合框中的选择的选项,作为 SetOption 方法设置参数中指定的选项列表中的数值位置。For options with settings that are choices in list boxes or combo boxes, specify the option's numeric position within the list as the setting argument for the SetOption method. 下面的示例将默认字段类型选项设置为 "自动编号"。The following example sets the Default Field Type option to AutoNumber.

Application.SetOption "Default Field Type", 5

如果要设置的选项是选项组中的成员,则只需指定该选项在组中的索引编号即可。To set an option that's a member of an option group, specify the index number of the option within the group. 下面的示例将 “选中行为” 设为“全部包含”:The following example sets Selection Behavior to Fully Enclosed:

Application.SetOption "Selection Behavior", 1

备注

退出 Microsoft Access 时,您就可以通过所有已更改的选项使用 SetOption 方法所有选项重都置为其原始设置。When you quit Microsoft Access, you can reset all options to their original settings by using the SetOption method on all changed options. 您可能想要创建公用变量来保存原始设置的值。You may want to create public variables to store the values of the original settings. 可以在窗体的Close事件过程中, 或在用户必须运行以退出应用程序的自定义退出过程中, 包含用于重置选项的代码。You might include code to reset options in the Close event procedure for a form, or in a custom exit procedure that the user must run to quit the application.

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.