SamarthSalunkhe
Board Regular
- Joined
- Jun 14, 2021
- Messages
- 103
- Office Version
- 2016
- Platform
- Windows
I'm using the below change event to prevent symbols from the textbox. I have tried to use it under Exit but it's not working.
can someone help me to validate this under the Exit event?
can someone help me to validate this under the Exit event?
VBA Code:
Private Sub TxtName_Change()
Dim LastPosition As Long
Const PatternFilter As String = "*[!0-9A-Za-z ]*"
Static LastText As String
Static SecondTime As Boolean
If Not SecondTime Then
With txtName
If .Text Like PatternFilter Then
MsgBox "Special Character is not allowed in this tab", vbExclamation, "Special Character Found"
SecondTime = True
.Text = LastText
.SelStart = LastPosition
Else
LastText = .Text
End If
End With
End If
SecondTime = False
End Sub