Padding Zeros

A

AJ

I am trying to insert a field and I would like it to insert 4 characters. So
I would like 0000 or 0001, 0002 to be inserted, NOT 0, 1, 2.

I am using VBA and would ike to start with 0000 and loop through 9999.

Can this be done? Or do I need to convert it on my Select (and if so, how?)

Thank you for your help!!!

AJ
 
G

Graham Mandeno

Hi AJ

A number doesn't have *any* characters, as such. It is merely the
representation of order or quantity.

When we *display* numbers, we use characters and convert the numeric value
to text.

In Access, the Format property of a field or textbox controls how numeric
values are displayed. If you set the Format property of the textbox
displaying your numbers to "0000" then they will always display with at
least four digits, including leading zeroes if necessary.
 
J

John W. Vinson

I am trying to insert a field and I would like it to insert 4 characters. So
I would like 0000 or 0001, 0002 to be inserted, NOT 0, 1, 2.

I am using VBA and would ike to start with 0000 and loop through 9999.

Can this be done? Or do I need to convert it on my Select (and if so, how?)

Thank you for your help!!!

AJ

You can *display* a Number (Long Integer, preferably) field with leading zeros
by simply setting its Format to "0000". It's not stored as such - 0001 and 1
and 01 and 0000000001 are all the same number! - but it'll give you the look.

Or, you can use a Text field with an Input Mask of "0000" to force entry of
four digits. It can be incremented with VBA code if that's what you want.
 
A

AJ

Hello and thank you for your quick replies -

The reason I am looking to do this is becuase I need to export it to a csv
file. So I want to export my table with the two fields.
Example csv:
FIELDA, 0000
FIELDB, 0001

I am creating the second field using a basic loop (increment by 1, insert,
increment, insert, ....) but right now I am getting in my csv:
FIELDA, 0
FIELDB, 1

Any thoughts or ideas??
Thanks again
AJ
 
J

John W. Vinson

Hello and thank you for your quick replies -

The reason I am looking to do this is becuase I need to export it to a csv
file. So I want to export my table with the two fields.
Example csv:
FIELDA, 0000
FIELDB, 0001

I am creating the second field using a basic loop (increment by 1, insert,
increment, insert, ....) but right now I am getting in my csv:
FIELDA, 0
FIELDB, 1

Don't export from the Table (its format will be ignored); instead create a
Query with a calculated field explicitly converting the Number field to a
String:

ExpFieldA: Format([FieldA], "0000")

and export from that query.
 

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