- Код: Выделить всё
' Отсечение недопустимых символов при вводе в поле
Public Sub CheckKeyPress(KeyAscii As Integer, FieldType As ADODB.DataTypeEnum)
Select Case FieldType
' Контроль ввода целочисленных полей
Case adInteger, adSmallInt, adUnsignedTinyInt
Select Case KeyAscii
Case 48 To 57, Is < 32
Case 45: If FieldType = adUnsignedTinyInt Then KeyAscii = 0
Case Else: KeyAscii = 0
End Select
' Контроль ввода полей с плавающей запятой
Case adCurrency, adDouble, adSingle, adNumeric
Select Case KeyAscii
Case 44, 46
If KeyAscii <> Asc(Mid$(Format$(1000, "#,0"), 2, 1)) Then
KeyAscii = Asc(Format(0, "."))
End If
Case 45, 48 To 57, Is < 32
Case Else: KeyAscii = 0
End Select
' Контроль ввода полей даты/времени
Case adDate, adDBTimeStamp
Select Case KeyAscii
Case 44 To 47: KeyAscii = Right$(Format$(2, "d."), 1) ' .,/ -> .
Case 58, 59: KeyAscii = Right$(Format$(0, "h:"), 1) ' ;: -> :
Case 48 To 57, Is <= 32
Case Else: KeyAscii = 0
End Select
End Select
End Sub