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

您可以使用InputMask屬性以方便資料輸入,並控制使用者可以在下拉式方塊控制項中輸入的值。You can use the InputMask property to make data entry easier and to control the values that users can enter in a combo box control. 可讀寫的 StringRead/write String.

語法Syntax

運算式輸入遮罩expression.InputMask

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

註解Remarks

輸入的遮罩很有幫助例如輸入遮罩顯示您如何確實輸入新號碼的電話號碼欄位的資料輸入作業: (___) ___-____Input masks are helpful for data-entry operations such as an input mask for a Phone Number field that shows you exactly how to enter a new number: (___) ___-____. 通常是用於輸入遮罩精靈將屬性設定為您的工作變得更容易。It is often easier to use the Input Mask Wizard to set the property for you.

InputMask 屬性可以包含多達三個區段以分號 (;) 分隔。The InputMask property can contain up to three sections separated by semicolons (;).

區段Section 描述Description
第一個First 指定輸入遮罩本身,例如,!(999) 999-9999。Specifies the input mask itself; for example, !(999) 999-9999. 如需可用來定義輸入的遮罩的字元的清單,請參閱下表。For a list of characters that you can use to define the input mask, see the following table.
第二個Second 指定了 Microsoft Access 是否當您輸入資料時在資料表中儲存了文字顯示字元。Specifies whether Microsoft Access stores the literal display characters in the table when you enter data. 如果您在這個區段使用了 0,所有的文字顯示字元 (例如,電話號碼輸入遮罩中的括號) 都會與數值一同儲存;如果您輸入了 1 或未在此區段中輸入任何資料,那麼只有輸入控制項中的字元會被儲存下來。If you use 0 for this section, all literal display characters (for example, the parentheses in a phone number input mask) are stored with the value; if you enter 1 or leave this section blank, only characters typed into the control are stored.
第三個Third 指定的字元,Access 會顯示您應該在其中輸入遮罩中輸入字元的空間。Specifies the character that Access displays for the space where you should type a character in the input mask. 關於這個區段,您可以使用任何字元;若要顯示零長度字串,使用一個包圍在雙引號 (" ") 中間的空格。For this section, you can use any character; to display an empty string, use a space enclosed in quotation marks (" ").

在 Visual Basic 中,您可以使用字串運算式來設定此屬性。In Visual Basic, you use a string expression to set this property. 例如,下列指定用於輸入電話號碼文字方塊控制項的輸入的遮罩。For example, the following specifies an input mask for a text box control used for entering a phone number.

Forms!Customers!Telephone.InputMask = "(###) ###-####"

當建立輸入遮罩時,可以使用特殊的字元以要求輸入特定的資料 (例如電話號碼的區域號碼),並要求其他資料為選擇性的 (如分機號碼)。When you create an input mask, you can use special characters to require that certain data be entered (for example, the area code for a phone number) and that other data be optional (such as a telephone extension). 這些字元指定您必須在輸入遮罩中為每一個字元輸入的資料類型 (如數字或字元)。These characters specify the type of data, such as a number or character, that you must enter for each character in the input mask.

您可以使用下列字元定義輸入遮罩。You can define an input mask by using the following characters.

字元Character 描述Description
0 數字 (0 到 9、 必要; 的項目加上 [+] 與減號 [?] 不允許)。Digit (0 to 9, entry required; plus [+] and minus [?] signs not allowed).
9 數字或空格 (不必要; 的項目加號與減號不允許)。Digit or space (entry not required; plus and minus signs not allowed).
# 數字或空格 (不必須輸入;在「編輯」模式下空格會以空白顯示,但是當資料儲存後空白會被移除;容許加號與減號)。Digit or space (entry not required; spaces are displayed as blanks while in Edit mode, but blanks are removed when data is saved; plus and minus signs allowed).
L 字母 (A 至 Z,必須輸入)。Letter (A to Z, entry required).
? 字母 (A 至 Z,選擇性輸入)。Letter (A to Z, entry optional).
A 字母或數字 (必須輸入)。Letter or digit (entry required).
a 字母或數字 (選擇性輸入)。Letter or digit (entry optional).
& 任何的字元或一個空格 (必須輸入)。Any character or a space (entry required).
C 任何的字元或一個空格 (選擇性輸入)。Any character or a space (entry optional).
. , : ; - / 小數點預留位置及千,日期和時間分隔符號。Decimal placeholder and thousand, date, and time separators. (使用的實際字元取決於 Windows [控制台] 的 [國別設定內容] 對話方塊中的設定值。)(The actual character used depends on the settings in the Regional Settings Properties dialog box in the Windows Control Panel).
< 使所有字元轉換成小寫。Causes all characters to be converted to lowercase.
> 使所有字元轉換成大寫。Causes all characters to be converted to uppercase.
! 使輸入遮罩從右至左顯示,而不是由左至右顯示。Causes the input mask to display from right to left, rather than from left to right. 輸入遮罩中的字元始終從左到右填滿遮罩。Characters typed into the mask always fill it from left to right. 您可以在輸入遮罩中的任何地方包含驚嘆號。You can include the exclamation point anywhere in the input mask.
\ 使接下來的字元以文字字元顯示 (例如,\A 顯示出來只有 A 而已)。Causes the character that follows to be displayed as the literal character (for example, \A is displayed as just A).

注意

[!注意事項] InputMask 屬性設定為"Password"的字會建立密碼項目的控制項。Setting the InputMask property to the word "Password" creates a password-entry control. 在控制項中輸入任何字元儲存為字元,但會顯示為星號 (*)。Any character typed in the control is stored as the character but is displayed as an asterisk (*). 您可以使用密碼輸入的遮罩以避免在螢幕上顯示所輸入的字元。You use the Password input mask to prevent displaying the typed characters on the screen.

當您在已經定義了輸入遮罩的欄位中輸入資料時,資料始終是在「取代」模式下輸入的。When you type data in a field for which you've defined an input mask, the data is always entered in Overtype mode. 如果您使用退格鍵刪除字元,字元會用空格來取代。If you use the Backspace key to delete a character, the character is replaced by a blank space.

如果您從一個已經定義過輸入遮罩的欄位中將文字移動到「剪貼簿」上去,即使您已經指定了它們不與資料一起儲存,文字顯示字元仍然會被複製。If you move text from a field for which you've defined an input mask onto the Clipboard, the literal display characters are copied, even if you have specified that they not be saved with data.

注意

[!注意事項] 只有您直接在控制項或下拉式方塊中輸入的字元都受到輸入遮罩。Only characters that you type directly in a control or combo box are affected by the input mask. 當您匯入資料、 執行巨集指令查詢,或在控制項中輸入字元,藉由設定 Visual Basic 中的控制項的Text屬性或使用 SetValue 巨集指令的巨集時,access 會略過任何輸入的遮罩。Access ignores any input masks when you import data, run an action query, or enter characters in a control by setting the control's Text property in Visual Basic or by using the SetValue action in a macro.

如果您已定義輸入的遮罩設定為相同的欄位的 Format 屬性, Format 屬性優先時顯示的資料。When you've defined an input mask and set the Format property for the same field, the Format property takes precedence when the data is displayed. 這表示即使您已儲存的輸入的遮罩,輸入的遮罩就會略過的資料是格式化並顯示。This means that even if you've saved an input mask, the input mask is ignored when data is formatted and displayed. 位於底層資料表的資料本身並沒有變更;Format 屬性僅對於資料的顯示方式有所影響而已。The data in the underlying table itself isn't changed; the Format property affects only how the data is displayed.

下表顯示一些有用的輸入的遮罩以及您可以在其中輸入的值的類型。The following table shows some useful input masks and the type of values that you can enter in them.

輸入遮罩Input mask 範例數值Sample values
(000) 000-0000(000) 000-0000 (206) 555-0248(206) 555-0248
(999) 999-9999(999) 999-9999 (206) 555-0248,() 555-0248(206) 555-0248, ( ) 555-0248
(000) AAA-AAAA(000) AAA-AAAA (206) 555-TELE(206) 555-TELE
#999#999 ? 20、 2000?20, 2000
>L 章節L? 000 L 0>L????L?000L0 GREENGR339M3,MAY R 452B7GREENGR339M3, MAY R 452B7
>L0L 0 L 0>L0L 0L0 T2F 8 M 4T2F 8M4
00000-999900000-9999 98115-98115 300798115-, 98115-3007
>L< 章節>L<?????????????? Maria、 BrendanMaria, Brendan
SSN 000-00-0000SSN 000-00-0000 SSN 555-55-5555SSN 555-55-5555
>LL00000-0000>LL00000-0000 DB51392-0493DB51392-0493

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