fixed length zero filled fields

D

Dennis L. Webster

I need to put a field on a form for input that is 7 characters in length, and
will add leading zeros to any input that is less than 7 characters. Can
anyone help me
 
J

Jeff Boyce

Dennis

Why do you believe you need leading zeros in a field? That is, what
business need are you attempting to solve by looking for a way to do this?

What data type is the underlying field in the table? Remember that
"0000001" and "1" are the same numeric value.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
O

Order2Chaos

You can try changing the format of the field to 0000000. But I think that
might just be superficial.

Otherwise you could consider using some Visual Basic to count the character
length "Len(Text)" and append the appropriate leading 0's. Try something like
this on an After Update Event maybe:

InputValue = [Forms]![TestForm]![Value]

[Forms]![TestForm]![Value] = Left("0000000",7 - Len(InputValue) & InputValue
 
J

John W. Vinson

You can try changing the format of the field to 0000000. But I think that
might just be superficial.

Otherwise you could consider using some Visual Basic to count the character
length "Len(Text)" and append the appropriate leading 0's. Try something like
this on an After Update Event maybe:

InputValue = [Forms]![TestForm]![Value]

[Forms]![TestForm]![Value] = Left("0000000",7 - Len(InputValue) & InputValue

Dennis L. Webster said:
I need to put a field on a form for input that is 7 characters in length, and
will add leading zeros to any input that is less than 7 characters. Can
anyone help me

A simpler (but much more obscure) method to update a Text field to have
leading zeros is to append the field's width of zeros, and use the Right()
function to trim off just enough characters:

Right("0000000" & [InputValue], 7)
 
M

michael collins

Dennis L. Webster said:
I need to put a field on a form for input that is 7 characters in length,
and
will add leading zeros to any input that is less than 7 characters. Can
anyone help me
 

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

Top