[User form] input text box, on tab fills to 5 figures 321 -
[User form] input text box, on tab fills to 5 figures  321 -
Thanks Thanks:  0
Likes Likes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 17

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

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Posts
    162
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    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. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    Leiden, The Netherlands
    Posts
    68
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #3
    Board Regular
    Join Date
    Mar 2002
    Posts
    162
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Oh yeah, this is great.
    I appreciate it. thanks!

    Dinictus.

  4. #4
    Board Regular
    Join Date
    Feb 2002
    Location
    Where the wild roses grow
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #5
    Board Regular
    Join Date
    Feb 2002
    Location
    Where the wild roses grow
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Oh man...

    Always a bridesmaid, never a bride...

  6. #6
    Board Regular
    Join Date
    Mar 2002
    Location
    Leiden, The Netherlands
    Posts
    68
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    sure, but I prefer your use of the Format function...

  7. #7
    Board Regular
    Join Date
    Feb 2002
    Location
    Where the wild roses grow
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #8
    Board Regular
    Join Date
    Mar 2002
    Posts
    162
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #9
    Board Regular
    Join Date
    Feb 2002
    Location
    Where the wild roses grow
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #10
    Board Regular
    Join Date
    Feb 2002
    Location
    Where the wild roses grow
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

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

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com