I want to exclude EndOfLine in a serie of TextFields (First Name, Last Name, etc.).
I already added code to delete duplicate spaces, leading and ending space(s), etc. But I cannot understand where to put the relevant code.
The idea is to:
a. get the “previous” contents,
b. check if there is one (or many) EndOfLine character(s),
Replace the newly added contents by the previous contents (step a),
Report the error to the user (something like “This field cannot hold Return character.”
Beside a nap, I spent the whole afternoon on this and I failed miserably [:(].
Trim only applies to whitespace found on either end of the text. If you’re trying to snip EOL out of the middle of the string you’ll have to implement per Dave’s method. Use TextChanged not KeyDown.
What I want to exclude is any EndOfLine character the user can Paste.
(because that gentle user Paste things ! And multiple lines are not visible in a single line TextField.)
Maybe this is not the place to do that. I may have to do that in the Modify or Add Card buttons (into a SQLite db) ?
[code]Function EditPaste() As Boolean
Dim Clip As New Clipboard
Dim Previous_Text As String
Previous_Text = Me.Text
If Clip.TextAvailable And InStr(Clip.Text,EndOfLine) > 0 Then
// There is an EndOfLine char in the Clipboard and the code skip this part
Clip.Text = Previous_Text
Clip.Close
a. Store the TextField before making any change,
b. Check if there is a Return inside the Clipboard
c. If there is a gremlin char, place the previous contents
d. If there is no gremlin character: paste the Clipboard.
Thanks for pushing the speed of my brain (to resolve the issue).
[code]Function EditPaste() As Boolean
Dim Clip As New Clipboard
Dim Previous_Text As String
Previous_Text = Me.Text
If Clip.TextAvailable Then
Dim cText As String
cText = ReplaceLineEndings(Clip.Text,EndOfLine)
If InStr(cText,EndOfLine) > 0 Then
Clip.Text = Previous_Text
Clip.Close
Else
Me.Text = Clip.Text
Clip.Close
End If
Suggest you add a Beep in the part where you reject the paste, and perhaps also show a message explaining why it was rejected (a red Label below the TextField would be where I’d put that).