[User form] input text box, on tab fills to 5 figures 321 -

Dinictus

Board Regular
Joined
Mar 19, 2002
Messages
162
Hi I`ve had some great help on a user form from Audiojoe today. I`ve come quite far but there are still a few things I can`t seem to figure out.

I`ve made a userform for data entry purposes.
Each textbox must be filled with 5 figures however sometimes the input is e.g. 321 What I want is that on tab (swith to the next textbox 00321 is filled in.
How can I get the form to do that?

Also what I would like is that when someone filles in 5 figures in the first textboxt, the cursor automatically switches to the next box.

My current source for a textbox:

Private Sub TBL1_Change()
Worksheets("sheet1").Range("B2").Value = TBL1
End Sub

Can anyone hand me some clue`s?

thanks.

Dinictus.
Holland
This message was edited by Dinictus on 2002-03-20 07:01
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
To expand figures to 5 digits, insert the following code in the "Exit" event of the Text Box:

L = Len(Me.TextBox1.Value)
If L < 5 Then
Me.TextBox1.Value = Application.Rept("0", 5 - L) & Me.TextBox1.Value
End If

To skip to the next Text Box after the 5th digit has been inserted, add the following code to the "Change" event:

If Len(Me.TextBox1.Value) = 5 Then Me.TextBox2.SetFocus

Both examples assume that the current textbox is named TextBox1 and the next textbox is named TextBox2.

Marc
 
Upvote 0
Private Sub TextBox1_Change()

If Len(TextBox1.Text) >= 5 Then TextBox2.SetFocus

End Sub

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

If KeyCode = vbKeyTab Then
TextBox1 = Format(TextBox1, "00000")
TextBox2.SetFocus
End If

End Sub
 
Upvote 0
Hoo-ah!! A better way is to delete:

Private Sub TextBox1_Change()

If Len(TextBox1.Text) >= 5 Then TextBox2.SetFocus

End Sub

and set the textbox1.autotab property to true


Still got it after all these years...
 
Upvote 0
So much help.... thanks, I have tears of joy.
(no smiley for that I see)

Can you elaborate on the format function?
This message was edited by Dinictus on 2002-03-20 07:46
 
Upvote 0
Sorry, I didn't mean for that "Hoo-ah!" to sound that egotistic, I was just pleased as it usually takes me two hours to find one answer, let alone two.

The format function is this part:

TextBox1 = Format(TextBox1, "00000")

It just says there must be five digits in the text box
 
Upvote 0
Hang on!!! I've thought of a third!! Who says brain cells die when you're struck by lightning!! Who said that swimming in that lake next to the power plant would be bad for me! Sure, my eyes have stung for 4 years and my nose is now located on my ***, but hey! Just put this code under the textbox1_keydown event
- it's all you need!!

If KeyCode = vbKeyTab Then TextBox1 = Format(TextBox1, "00000")
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,211
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top