Textbox format question

  • Thread starter Thread starter KD
  • Start date Start date
K

KD

I am unable to enter more that one character (2.00 but not 26.00) in a
textbox. I have the format set to ###.00 in another procedure. I
think this is the procedure that is causing the problem. Is there a
format length in here?

Private Sub TextBox80_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc("0") To Asc("9")
If InStr(1, Me.TextBox80.Text, "$") > 0 Or
Me.TextBox80.SelStart > 0 Then
KeyAscii = 0
End If
Case Asc(".")
If InStr(1, Me.TextBox80.Text, ".") > 0 Then
KeyAscii = 0
End If
Case Else
KeyAscii = 0
End Select
End Sub


Thanks,
James
 
This seems to work

Private Sub TextBox80_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc("0") To Asc("9")
If InStr(1, Me.TextBox80.Text, "$") > 0 Then
KeyAscii = 0
End If
Case Asc(".")
If InStr(1, Me.TextBox80.Text, ".") > 0 Then
KeyAscii = 0
End If
Case Else
KeyAscii = 0
End Select
End Sub

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)
 
Any ideas what could be causing this limitation? I am confounded.
Here is the formatting procedure. I trigger a set focus before calling
so that the user sees formatting consistently.

Private Sub TextBox80_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If TextBox80 <> "" Then
TextBox80.Value = Format(Me.TextBox80.Value, "###.00")
Else
TextBox80.Value = Format(Me.TextBox80.Value, "0")
End If
End Sub
 
Back
Top