Decimal Points & TextBoxes


Posted by Angie Dickinson on September 12, 2001 6:17 AM

Hi Everyone,

I have a label which looks like this: -------.--
The dashes represent 2 textboxes sitting on the label. This is to be used to input a premium, eg- 250.00 What i want to do is when i input the 250 and press the decimal point it skips to the next textbox without registering the decimal point since i already have it on the label, is there any way to achieve this or can a different route be taken to arrive at the same result?

Angie

Posted by Daniel K on September 12, 2001 8:16 AM

Say the integer part of your number is entered into a textbox called textbox1 and the decimal part is entered into a textbox called textbox2. Try some code like this in your form:-

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 110 Then TextBox2.SetFocus
End Sub

Private Sub TextBox2_Change()
TextBox2.Text = Replace(TextBox2.Text, ".", "")
End Sub

Hope it helps,
Dan.



Posted by Russell Hauf on September 12, 2001 9:45 AM

You could also get away with just code in the one text box. Try this:

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

If KeyCode = 110 Then

KeyCode = 0
TextBox2.SetFocus

End If

End Sub

Hope this helps,

Russell