Update data in field to fixed length

L

Lori

In Access 97, I have a form using a single table as a data
source. I have a field called Policy Nbr. The data in
this field must be 7 characters long. Is there a way that
if fewer than 7 characters is entered, I can have Access
append zeros to the beginning of the number to make the
field be 7 characters long?

For example, if 9345 is entered, can Access convert this
to 0009345 and store it as such?

Thanks! Lori
 
F

fredg

In Access 97, I have a form using a single table as a data
source. I have a field called Policy Nbr. The data in
this field must be 7 characters long. Is there a way that
if fewer than 7 characters is entered, I can have Access
append zeros to the beginning of the number to make the
field be 7 characters long?

For example, if 9345 is entered, can Access convert this
to 0009345 and store it as such?

Thanks! Lori

If the [Policy Nbr] field's datatype is Number, Access will drop
zero's to the left of the value.
Simply leave the data as is, but set the format property of the
control to
0000000

If it is a field that will never be used for calculations, the field
datatype should be Text, not Number.
In the Control's AfterUpdate event:
[ControlName] = string(7-Len([FieldName]),"0") & [FieldName]
 

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