![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Mar 2002
Posts: 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 ] |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Mar 2002
Location: Leiden, The Netherlands
Posts: 68
|
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 |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Mar 2002
Posts: 162
|
Oh yeah, this is great.
I appreciate it. thanks! Dinictus. |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: Where the wild roses grow
Posts: 285
|
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 |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: Where the wild roses grow
Posts: 285
|
Oh man...
Always a bridesmaid, never a bride... |
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Mar 2002
Location: Leiden, The Netherlands
Posts: 68
|
sure, but I prefer your use of the Format function...
|
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Feb 2002
Location: Where the wild roses grow
Posts: 285
|
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... |
|
|
|
|
|
#8 |
|
Board Regular
Join Date: Mar 2002
Posts: 162
|
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 ] |
|
|
|
|
|
#9 |
|
Board Regular
Join Date: Feb 2002
Location: Where the wild roses grow
Posts: 285
|
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 |
|
|
|
|
|
#10 |
|
Board Regular
Join Date: Feb 2002
Location: Where the wild roses grow
Posts: 285
|
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") |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|