![]() |
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 |
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 " 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 |
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. |
All times are GMT +1. The time now is 07:30 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com