OptionButton.DefaultValue 屬性 (Access)OptionButton.DefaultValue property (Access)

會指定在建立新的記錄時自動欄位中輸入值。Specifies a value that is automatically entered in a field when a new record is created. 例如,地址] 資料表中,您可以設定 [城市] 欄位的預設值為紐約。For example, in an Addresses table, you can set the default value for the City field to New York. 當使用者將記錄新增至表格時,他們可以接受此值或輸入不同的城市名稱。When users add a record to the table, they can either accept this value or enter the name of a different city. 可讀寫 的字串Read/write String.

語法Syntax

運算式預設值expression.DefaultValue

_運算式_代表**OptionButton** 物件的變數。expression A variable that represents an OptionButton object.

註解Remarks

DefaultValue 屬性適用於所有資料表欄位具有自動編號或 OLE 物件的資料類型欄位除外。The DefaultValue property applies to all table fields except those fields with the data type of AutoNumber or OLE Object.

DefaultValue 屬性指定文字或自動輸入控制項或欄位中建立新的記錄時的運算式。The DefaultValue property specifies text or an expression that's automatically entered in a control or field when a new record is created. 例如,如果您將文字方塊控制項的 DefaultValue 屬性為 =Now(),此控制項會顯示目前的日期和時間。For example, if you set the DefaultValue property for a text box control to =Now(), the control displays the current date and time. DefaultValue 屬性設定的最大長度為 255 個字元。The maximum length for a DefaultValue property setting is 255 characters.

DefaultValue屬性不會套用至] 核取方塊、 選項按鈕或切換按鈕控制項選項群組中時。The DefaultValue property doesn't apply to check box, option button, or toggle button controls when they are in an option group. 不過,它沒有適用於選項群組本身。However, it does apply to the option group itself.

在 Visual Basic 中使用的字串運算式來設定此屬性的值。In Visual Basic, use a string expression to set the value of this property. 例如,下列程式碼會設定名為"現金。"的PaymentMethod文字方塊控制項的DefaultValue屬性For example, the following code sets the DefaultValue property for a text box control named PaymentMethod to "Cash."

Forms!frmInvoice!PaymentMethod.DefaultValue = """Cash"""

注意

[!注意事項] 若要使用 Visual Basic 設定欄位的這個屬性,使用 ADO DefaultValue 屬性或 DAO DefaultValue 屬性。To set this property for a field by using Visual Basic, use the ADO DefaultValue property or the DAO DefaultValue property.

只有當您新增新的記錄時才會套用 DefaultValue 屬性。The DefaultValue property is applied only when you add a new record. 如果您變更 DefaultValue 屬性,將變更不是自動套用至現有的記錄。If you change the DefaultValue property, the change isn't automatically applied to existing records.

如果您將表單控制項繫結至也有表格中所定義的 DefaultValue 屬性設定的欄位的 DefaultValue 屬性,控制設定會覆寫 [表格] 設定。If you set the DefaultValue property for a form control that's bound to a field that also has a DefaultValue property setting defined in the table, the control setting overrides the table setting.

如果您從欄位清單拖曳欄位來建立控制項,該欄位的 DefaultValue 屬性設定,定義在表格中,會套用至表單上控制項雖然控制項的 DefaultValue 屬性設定會保留空白。If you create a control by dragging a field from the field list, the field's DefaultValue property setting, as defined in the table, is applied to the control on the form although the control's DefaultValue property setting will remain blank.

一個控制項可以為另一個控制項提供預設值。One control can provide the default value for another control. 例如,如果您將一個控制項的 DefaultValue 屬性設定成以下運算式,控制項的預設值會設定成 txtShipTo 控制項的 DefaultValue 屬性設定值。For example, if you set the DefaultValue property for a control to the following expression, the control's default value is set to the DefaultValue property setting for the txtShipTo control.

=Forms!frmInvoice!txtShipTo

如果控制項位在同一個表單中,預設值來源的控制項必須比包含運算式的控制項要早出現在 Tab 鍵順序中。If the controls are on the same form, the control that's the source of the default value must appear earlier in the tab order than the control containing the expression.

支援和意見反應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.