kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
This code was written for me by one of the gurus here way back. It's working great just that there is some behavior of it that I wish I could improve upon it.
When I want to edit already keyed data in the textbox , the cursor jumps to the last character in the TextBox.
For example if I have "NICE BOOK" inside the TextBox, except I place the cursor in front of the "K", the cursor will always jump to be in front of the "K" when I try editing behind the K.
I want it to stay as I edit just like making corrections in a text editor.
How do I get it to do what I want?
Thanks in advance.
When I want to edit already keyed data in the textbox , the cursor jumps to the last character in the TextBox.
For example if I have "NICE BOOK" inside the TextBox, except I place the cursor in front of the "K", the cursor will always jump to be in front of the "K" when I try editing behind the K.
I want it to stay as I edit just like making corrections in a text editor.
How do I get it to do what I want?
Code:
Private Sub freg2_Change()
Static LastText$
Static SecondTime As Boolean
If Not SecondTime Then
With freg2
If .Text Like "*[!A-Za-z. -1-5]*" Or .Text Like "*..*" Or _
.Text Like "*--*" Or .Text Like "* *" Or .Text Like "*-.*" Or _
.Text Like "* .*" Or .Text Like "[. -]" Or .Text Like "[1-5]" Then
Call Beep
SecondTime = True
.Text = LastText
Else
LastText = .Text
End If
For i = 1 To Len(.Text) - 1
If Mid(.Text, i, 2) Like ".[A-Za-z1-5]" Then
.Text = Application.Replace(.Text, i + 1, 0, " ")
End If
Next i
.Text = Replace(Replace(Replace(.Text, " - ", "-"), "- ", "-"), " -", "-")
End With
End If
SecondTime = False
End Sub
Thanks in advance.