How to put any character in a textbox EXCEPT the backslash ?
Printable View
How to put any character in a textbox EXCEPT the backslash ?
Do you need to remove all the "\" or do you want these to be left in a variable?
Try this to disallow a "\" from being entered into the TextBox:
[Edited by SonGouki on 04-29-2000 at 05:16 PM]Code:Private Sub Text1_Change()
Dim lPrevPos As Long
If InStr(1, Text1.Text, "\") Then
lPrevPos = Text1.SelStart - 1
Text1.Text = Replace(Text1.Text, "\", vbNullString)
If lPrevPos > Len(Text1.Text) Then
Text1.SelStart = Len(Text1.Text)
Else
Text1.SelStart = lPrevPos
End If
End If
End Sub
Or can do something like this
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 92 Then
KeyAscii = 0
End If
End Sub
mlana,
That will work fine for regular typing into the TextBox, but is useless when the user pastes. My code disallows the undesired string completely, try it out ;)