2016-08-14 20 views
1

在表單上,​​我有13個textbox。當用戶點擊保存按鈕時,Access調用API並將這些文本框中的值傳遞給API(通過HTTP REST)不允許在MS Access的所有文本框中輸入特定字母

有些字符不允許通過API保存,如"。因此我想限制用戶輸入這些字符。

當前我創建了一個PublicFunctionKeyPress調用的事件來檢查字符是否允許。但是我必須從每個textboxKeyPress事件中調用該函數。 有沒有辦法在所有的文本框中不允許"

功能

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代表"

回答

3

你有三編輯於Form的等級?順便說一句,大多數時間用戶複製和粘貼,這將允許用戶輸入那些不需要的字符(只是提醒:))

Private Sub Form_KeyPress(KeyAscii As Integer) 
    If ActiveControl.ControlType = 109 Then 'only for textboxes 
     KeyAscii = CharsNotAllowed(KeyAscii) 
    End If 
End Sub 
+0

需要將此代碼添加到每個「子窗體」。 –

相關問題