Disabling multiline fields in MS Access

Is there a way to disable multiline entries in a text field (i.e., I would like to prevent my users from doing ctrl-enter to get a new line)?

+3
source share
6 answers

I was able to do this using the KeyPress event. Here is a sample code:

Private Sub SingleLineTextBox_ KeyPress(ByRef KeyAscii As Integer)
    If KeyAscii = 10 _
        or KeyAscii = 13 Then
            '10 -> Ctrl-Enter. AKA ^J or ctrl-j
            '13 -> Enter.      AKA ^M or ctrl-m
        KeyAscii = 0  'clear the the KeyPress
    End If
End Sub
+5
source

, ( , Access, '97, ) key-up VBA. , AJAX, -, , , , , , onMouseMove .

+3

KeyPress , , . ( OnChange ).

, CrLf, AfterUpdate. :

  If InStr(Me!MyMemoControl, vbCrLf) Then
     Me!MyMemoControl = Replace(Me!MyMemoControl, vbCrLf, vbNullString)
  End If

, vbCrLf ( Chr (10) Chr (13)) vbNullString ( ).

, , . , AfterUpdate .

+2

, vbscript , chr (13) vbCrLf.

0

, ,

NOT LIKE "*"+Chr(10)+"*" OR "*"+Chr(13)+"*"

, , , Access .

0

Thanks to Jan and BIBD. I created a public section based on your answer, which can be reused.

Public Sub PreventNewlines(ByRef KeyAscii As Integer)
    If KeyAscii = 10 Or KeyAscii = 13 Then KeyAscii = 0
End Sub

Private Sub textbox_KeyPress(KeyAscii As Integer)
    Call PreventNewlines(KeyAscii)
End Sub

Screen flickering should never be a problem, since these are processed events, not a constant poll (and this additionally limits the area to one control). It seems to me a wrong argument, since each text editor executes some code for each keystroke.

thank

0
source

Source: https://habr.com/ru/post/1696472/


All Articles