Issue with form field lengths

  • Thread starter Thread starter roachware
  • Start date Start date
R

roachware

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
 
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
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top