Results 1 to 13 of 13

Thread: vb for Excel 2k

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    5

    vb for Excel 2k

    I have created a userform containing a button and a solitary textbox. I want users to enter a 4-digit number in the text box and then click the button. My problem is validating the text box so that it only accepts numeric values. If any one can help I would be grateful.

  2. #2
    Lively Member
    Join Date
    Sep 2001
    Location
    US
    Posts
    115
    Are you using Excel as your Database or ms access?

  3. #3
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    lol, clueless

    VB Code:
    1. Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    2. If KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Then
    3. Else
    4.     KeyAscii = 0
    5. End If
    6. End Sub


  4. #4
    Lively Member
    Join Date
    Sep 2001
    Location
    US
    Posts
    115

    Wink

    WHAT......3,668 post later.....

    I only wonder how good you were in the begining!

  5. #5
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    heheheh


    when i was 13 i wasn't all that bad, i was just starting to pick it up

    i'm 15 know and i'm confident with VB

    it just takes a bit of time

  6. #6
    Lively Member
    Join Date
    Sep 2001
    Location
    US
    Posts
    115

    Smile

    Well you seem very good.....

    I only wish I had started sooner......

  7. #7
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    thanks

    why, how old are you (if you don't mind me asking )?

  8. #8
    Lively Member
    Join Date
    Sep 2001
    Location
    US
    Posts
    115

    Unhappy

    I'm 24 and will be 25 in a couple of weeks....(Over the hill)

  9. #9
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    heheheh

    you're really old

    j/k

  10. #10
    Lively Member
    Join Date
    Sep 2001
    Location
    US
    Posts
    115

    Smile

    I missed a question: Why? Better understanding, better pay....it would have given me the opportunity to learn other things computer related


    PS
    I was taken by the age question...I haven't really wanted to celebrate my birthday since I was 22

  11. #11
    Lively Member
    Join Date
    Sep 2001
    Location
    US
    Posts
    115

    Talking

    I'm SURE you will do well.......you might even succeed in making some VB professors double check their knowledge on the subject once you get in college...(This makes them very uncomfortable, I've seen it happen....its kindve of funny)

    I was hoping that maybe you could help me with a question I posted earlier on the forum.

    How much do you know about Data environment?

    I have a "Beginners Question", so dont laugh!!!!!!

    I want to open connection1 through programming code so that I can use app.path, however it looks like you can only set the connection by right clicking and going down to properties(to establish the connection) and then later adding the command

  12. #12

    Thread Starter
    New Member
    Join Date
    Dec 2001
    Posts
    5
    i'm new to vb and currently i have this on my button

    Private Sub BtnAccept_Click()
    If Len(TextBox1) Or Len(TextBox2) Or Len(TextBox3) Or Len(TextBox4) < 4 Then
    CreditCardDetails.Hide
    CreditCardDetails.Show
    Else
    answer = MsgBox("Do You Wish To Proceed", vbYesNo, "Warning")
    If answer = vbYes Then
    CreditCardDetails.Hide
    Application.Run "'GOL User.xls'!AddOrderToList"
    Thankyou.Show
    Else
    CreditCardDetails.Hide
    TextBox1 = ""
    TextBox2 = ""
    TextBox3 = ""
    TextBox4 = ""
    End If
    End If
    End Sub

    how would I encorporate that previous bit of code into this to check all four textboxes

  13. #13
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    in VBA

    just put that code in the keypress events of each text box

    or in vb use, this:

    VB Code:
    1. Private Sub Text1_KeyPress(KeyAscii As Integer)
    2. KeyAscii = CheckIt(KeyAscii)
    3. End Sub
    4. Private Sub Text2_KeyPress(KeyAscii As Integer)
    5. KeyAscii = CheckIt(KeyAscii)
    6. End Sub
    7. Private Sub Text3_KeyPress(KeyAscii As Integer)
    8. KeyAscii = CheckIt(KeyAscii)
    9. End Sub
    10. Private Sub Text4_KeyPress(KeyAscii As Integer)
    11. KeyAscii = CheckIt(KeyAscii)
    12. End Sub
    13. Function CheckIt(KeyAscii As Integer) As Integer
    14. If KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Then
    15.     CheckIt = KeyAscii
    16. Else
    17.     CheckIt = 0
    18. End If
    19. End Function


Posting Permissions

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



Click Here to Expand Forum to Full Width