Access 2000. Macro to add leading zero

bigceedee

New Member
Joined
Sep 23, 2004
Messages
8
I have a table with a column labeled company code (3rd column over) that when I append data records, does not insert the leading zero, for a 3-digit character, even though my column is a text column. I know Access considers this a placeholder but this leading zero is truly needed.l I want to create my macro to add one leading zero to all 2-digit codes in this column. How can this be done?
Bigceedee
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
This can be done via an Update Query. PLEASE MAKE A COPY OF YOUR TABLE BEFORE YOU DO THIS, IN CASE OF A MISTAKE!

1. Create a new query, and add the "Code" field (I will call it "Code" for this example).

2. Then add this calculated field: Len(
Code:
)[/b]

3. Add this criteria to this calculated field: [b]<3[/b]
This will return all records where the Code is less than 3 characters long

4. Change the query type to "Update Query" (click on the icon of the Pencil with Exclamation point in the query toolbar, and select "Update Query")

5. You will see a new line labeled "Update To" in the query builder.  Under your "Code" field, enter this expression in the "Update To" line:
[b]Left("000",3-Len([Code])) & [Code][/b]

6. Click on the Run button (red exclamation point).  It will warn you that you are about to update records.  Select yes.  Your records should now be updated.
 
Upvote 0
Jim

How about just using Format(
Code:
, "000") for the update?
 
Upvote 0
Jim

How about just using Format(
Code:
, "000") for the update?[/quote]
Yes, that would work also, and is a little shorter.

BTW, who is Jim??? :-?
 
Upvote 0

Forum statistics

Threads
1,221,821
Messages
6,162,157
Members
451,750
Latest member
pnkundalia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top