ComboBox.Format 屬性 (Access)ComboBox.Format property (Access)

您可以使用 Format 屬性自訂數字、日期、時間和文字的顯示及列印方式。You can use the Format property to customize the way numbers, dates, times, and text are displayed and printed. 可讀寫的 StringRead/write String.

語法Syntax

運算式格式expression.Format

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

註解Remarks

您可以使用下列其中一個預先定義的格式,或者您可以使用格式符號來建立自訂格式。You can use one of the predefined formats, or you can create a custom format by using formatting symbols.

Format 屬性會對不同資料類型使用不同的設定。The Format property uses different settings for different data types. 如需有關特定資料類型設定的詳細資訊,請參閱下列主題:For information about settings for a specific data type, see one of the following topics:

在 Visual Basic 中,輸入一個字串運算式,對應至下列其中一個預先定義的格式,或輸入自訂格式。In Visual Basic, enter a string expression that corresponds to one of the predefined formats, or enter a custom format.

Format 屬性會影響僅限資料的顯示方式。The Format property affects only how data is displayed. 它不會影響儲存資料的方式。It doesn't affect how data is stored.

Microsoft Access 提供了預先定義的日期/時間、數字及貨幣、文字及備註以及是/否資料類型等的格式。Microsoft Access provides predefined formats for Date/Time, Number and Currency, Text and Memo, and Yes/No data types. 預先定義的格式是根據按兩下 Windows [控制台] 中的 [地區選項來指定國家/地區而定。The predefined formats depend on the country/region specified by double-clicking Regional Options in the Windows Control Panel. Access 會顯示所選取的國家/地區的適當格式。Access displays formats appropriate for the country/region selected. 例如,在 [一般] 索引標籤上選取 [英文 (美國) ,1234.56 在貨幣格式顯示成 $ 1,234.56、 但英文 (英國) 在 [一般] 索引標籤上選取時,會顯示為 1,234.56。For example, with English (United States) selected on the General tab, 1234.56 in the Currency format appears as $1,234.56, but when English (British) is selected on the General tab, the number appears as 1,234.56.

如果您在資料表設計檢視中設定欄位的Format屬性,Access 會使用該格式來顯示資料工作表中的資料。If you set a field's Format property in table Design view, Access uses that format to display data in datasheets. 它同時還會將欄位的 Format 屬性套用為表單與報表上的新控制項。It also applies the field's Format property to new controls on forms and reports.

您可以在任何資料類型的自訂格式中使用下列符號。You can use the following symbols in custom formats for any data type.

符號Symbol 意義Meaning
(空格)(space) 將空格以文字字元顯示。Display spaces as literal characters.
"ABC""ABC" 將雙引號內的任何字元以文字字元顯示。Display anything inside quotation marks as literal characters.
! 強迫向左對齊而不向右對齊。Force left alignment instead of right alignment.
* 將可用的空格填滿下一個字元。Fill available space with the next character.
\ 將下一個字元以文字字元顯示。Display the next character as a literal character. 您也可以在文字前後放置雙引號來顯示文字字元。You can also display literal characters by placing quotation marks around them.
[ color ][ color ] 用中括號之間指定的色彩顯示格式化的資料。Display the formatted data in the color specified between the brackets. 可用的色彩有:黑色、藍色、綠色、青色、紅色、洋紅、黃色、白色。Available colors: Black, Blue, Green, Cyan, Red, Magenta, Yellow, White.

您不能將數字及貨幣資料類型的自訂格式符號與日期/時間、是/否或文字及備註的格式符號互相混合。You can't mix custom formatting symbols for the Number and Currency data types with Date/Time, Yes/No, or Text and Memo formatting symbols.

如果您已定義輸入的遮罩設定 Format 屬性為相同的資料, Format 屬性優先時資料會顯示與就會略過輸入的遮罩。When you have defined an input mask and set the Format property for the same data, the Format property takes precedence when the data is displayed and the input mask is ignored. 例如,如果您在資料表「設計」檢視中建立「密碼」輸入遮罩,同時也設定相同欄位的 Format 屬性;無論是在資料表或是在表單上的控制項中,會根據 Format 屬性略過「密碼」輸入遮罩,並顯示資料。For example, if you create a Password input mask in table Design view and also set the Format property for the same field, either in the table or in a control on a form, the Password input mask is ignored and the data is displayed according to the Format property.

範例Example

下列三個範例使用預先定義的格式設定Format屬性。The following three examples set the Format property by using a predefined format.

Me!Date.Format = "Medium Date" 
 
Me!Time.Format = "Long Time" 
 
Me!Registered.Format = "Yes/No"

下列範例會使用自訂格式設定Format屬性。The following example sets the Format property by using a custom format. 此格式來顯示日期為Jan 2018This format displays a date as Jan 2018.

Forms!Employees!HireDate.Format = "mmm yyyy"

下列範例會示範 Visual Basic 函數,這個函數使用貨幣格式來設定數字資料的格式,並將文字資料設定為全大寫。The following example demonstrates a Visual Basic function that formats numeric data by using the Currency format and formats text data entirely in capital letters. 函式會從名為TaxRefund未結合控制項的OnLostFocus事件呼叫。The function is called from the OnLostFocus event of an unbound control named TaxRefund.

Function FormatValue() As Integer 
    Dim varEnteredValue As Variant 
 
    varEnteredValue = Forms!Survey!TaxRefund.Value 
    If IsNumeric(varEnteredValue) = True Then 
        Forms!Survey!TaxRefund.Format = "Currency" 
    Else 
        Forms!Survey!TaxRefund.Format = ">" 
    End If 
End Function

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