1
在表單上,我有13個textbox
。當用戶點擊保存按鈕時,Access調用API並將這些文本框中的值傳遞給API(通過HTTP REST)不允許在MS Access的所有文本框中輸入特定字母
有些字符不允許通過API保存,如"
。因此我想限制用戶輸入這些字符。
當前我創建了一個Public
Function
從KeyPress
調用的事件來檢查字符是否允許。但是我必須從每個textbox
KeyPress
事件中調用該函數。 有沒有辦法在所有的文本框中不允許"
?
功能
Public Function CharsNotAllowed(myChar As Integer) As Integer
If myChar = 34 Then
Beep 'Let the user know they hit an illegal key
CharsNotAllowed = 0 'Don't let the keystroke through
Else
CharsNotAllowed = myChar
End If
End Function
函數調用
Private Sub StudentName_KeyPress(KeyAscii As Integer)
KeyAscii = CharsNotAllowed(KeyAscii)
End Sub
Private Sub StudentClass_KeyPress(KeyAscii As Integer)
KeyAscii = CharsNotAllowed(KeyAscii)
End Sub
'and so on for all the 13 text boxes
注:34
代表"
需要將此代碼添加到每個「子窗體」。 –