kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
Hello good morning/afternoon/evening.
I have this code here that I want to do a few amendments and I need your help with that.
I want to achieve two goals but if I can get at least one goal, I will be very happy.
1. When I select all the contents of the textbox and press a key afterwards, I want to replace the pressed character with the highlighted content - just like it is with text editors.
2. On this line:
When I press keys after all 8 characters inside the textbox, the last character keeps being replaced with whatever new character or key pressed.
How do I avoid that?
If I want to display alert while there are 8 characters inside already and I press a key again?
I have this code here that I want to do a few amendments and I need your help with that.
I want to achieve two goals but if I can get at least one goal, I will be very happy.
1. When I select all the contents of the textbox and press a key afterwards, I want to replace the pressed character with the highlighted content - just like it is with text editors.
2. On this line:
Code:
Case Is > 7 : .Text = Left (.Text, 7)
How do I avoid that?
If I want to display alert while there are 8 characters inside already and I press a key again?
Code:
Private Sub TextBox1_KeyPress (ByVal KeyAscii As MSForms.ReturnInteger)
With TextBox1
KeyAscii = KeyAscii * -CLong (Chr (KeyAscii) Like "[0-9]")
Select Case Len (.Text)
Case Is = 2 : .Text = .Text & "-"
Case Is = 5 : .Text = .Text & "-"
Case Is > 7 : .Text = Left (.Text, 7)
End Select
End With
End Sub