Textbox format question

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
 
B

Bob Phillips

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)
 
K

KD

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top