AlexanderBB
Well-known Member
- Joined
- Jul 1, 2009
- Messages
- 2,099
- Office Version
- 2019
- 2010
- Platform
- Windows
Having trouble getting my text box to behave.
I want to restore the original text (which always will exist), if the user exits entering nothing.
Also limit the input to numbers only. That bit works ok, as does the Change event.
The Exit event is the problem. Even though Len = 0 and tmpText contains the value, the text box does not show it.
I am a bit fuzzzy on the ".text' part , which I know has some relevance, but I've tried all combinations and no difference.
I want to restore the original text (which always will exist), if the user exits entering nothing.
Also limit the input to numbers only. That bit works ok, as does the Change event.
The Exit event is the problem. Even though Len = 0 and tmpText contains the value, the text box does not show it.
I am a bit fuzzzy on the ".text' part , which I know has some relevance, but I've tried all combinations and no difference.
Code:
Private Sub TextBox1_Change()
On Error GoTo quit
Frame2.lblRed.BackColor = RGB(TextBox1, 0, 0)
Frame2.btnSet.BackColor = RGB(TextBox1, TextBox2, TextBox3)
ColourPicked = Frame2.btnSet.BackColor
quit:
End Sub
Private Sub TextBox1_Enter()
tmpText = TextBox1.text
'Debug.Print "Enter " & tmpText
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'Debug.Print "Length"; Len(TextBox1)
If Len(TextBox1) = 0 Then
TextBox1 = tmpText
End If
'Debug.Print "Exit" & tmpText
End Sub
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii = Restrict(KeyAscii)
End Sub
Private Function Restrict(KeyAscii)
Select Case KeyAscii
Case Asc("0") To Asc("9")
Restrict = KeyAscii
Case Else
KeyAscii = 0
End Select
End Function