+ Reply to Thread
Results 1 to 3 of 3

Issue with form field lengths

  1. #1

    Issue with form field lengths

    I am doing an order information form in VBA and have an area for credit
    card numbers. We take all major credit cards, and so I have the card
    number broken up into 4 fields. The idea is that you do not need to
    press the tab button to go on to the next field, it will setfocus in a
    macro...but is there a way to test for a length of a certain number of
    digits in a field? (So if their are 4 numbers in textbox1, then
    setfocus textbox2) Right now I am using if then statements to
    determine if the number typed in is over 999, but this is flawed for
    discover cards, because the 2nd set of digits is usually 0000 for the
    number. Any ideas? Please post code example. Thanks


  2. #2
    Dan Gardner
    Guest

    RE: Issue with form field lengths

    Try the following,

    Dim info as string
    dim LengthOfString as integer

    info = Userform1.textbox1.text

    LengthOfString = Len(info)

    if LengthofString > 4 then

    Bla Bla BLa

    end if

    Hopefully that helps

    If you want to constantly loop on each change even with in the text boxes I
    would then create a class of textboxes and put the length code in the class
    you can get class help at

    httP://j-walk.com/ss/excel/tips/tip44.htm



    "[email protected]" wrote:

    > I am doing an order information form in VBA and have an area for credit
    > card numbers. We take all major credit cards, and so I have the card
    > number broken up into 4 fields. The idea is that you do not need to
    > press the tab button to go on to the next field, it will setfocus in a
    > macro...but is there a way to test for a length of a certain number of
    > digits in a field? (So if their are 4 numbers in textbox1, then
    > setfocus textbox2) Right now I am using if then statements to
    > determine if the number typed in is over 999, but this is flawed for
    > discover cards, because the 2nd set of digits is usually 0000 for the
    > number. Any ideas? Please post code example. Thanks
    >
    >


  3. #3

    Re: Issue with form field lengths

    Damn! I feel like a dumbass for not catching that! Thanks! I am sure
    it will work like a champ, and yes I will check the class link out,
    thank you Dan.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1