Link to home
Start Free TrialLog in
Avatar of mrong
mrong

asked on

How to keep leading zeros in Crystal Report

Greetings,

I have a number field(in '0000' format) in Access 2000. Once I populated the data on Crystal Report Viewer, I got '1' instead of '0001'. What do I need to get the format('0000') I want?

Thanks.
Avatar of frodoman
frodoman
Flag of United States of America image

In Crystal you'll need to put a formula on the report instead of the datafield itself.  Create a formula with this:

Right('0000'+{table.datfield},4)

This will append four zeros in front of your data (e.g.: 00001) and then will return the four rightmost characters (0001).


Avatar of mrong
mrong

ASKER

I got error msg "the string is required->Project.ProjectID"

When I try to save the following formular on the report:

Right('0000'+{Project.ProjectID},4)

Thx.
You can also use the ToText function to accomplish this.

Create a formula and this code:

ToText({table.field},"0000");

This will accomplish the same thing as frodo's post, just another way to skin a cat so to speak.
Should be: Right('0000'+ToText({Project.ProjectID}),4)

Sorry - I'm not that familiar with the Access "format" and I thought it was already in text form.

Note that bdreed's suggestion is equally good.
SOLUTION
Avatar of bdreed35
bdreed35
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrong

ASKER

frodoman,

Your formula didn't give me the right data->'3.0' instead of '0023'.
I am trying bdreed35's formula.
Avatar of mrong

ASKER

Same output by using bdreed35's formula.
If you put just the field itself {Project.ProjectID} on the report what do you see in this example?  23?  2.3?
Avatar of mrong

ASKER

I see '23' if I put {Project.ProjectID} itself.
I see '3.0' if I use your formula.

Thanks.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrong

ASKER

what do you mean by dropdown?
Thanks.
In the formula editor you can (probably) choose between "Crystal Syntax" and "Basic Syntax".  If there is no such choice for you then probably you have an older version of crystal in which case it doesn't matter.

As long as you don't have anything on your formula editor that says "Basic Syntax" then you're fine - please do as I suggested and let me know the outcome.
Avatar of mrong

ASKER

frodoman,

I use Crystal Syntax in the dropdown menu for the formula, but I still get the same output ('3.0') by using  'right("0000"&23,4)'.
Thanks.
Avatar of mrong

ASKER

I got it. it shoud be
ToText ({table.field},"000000")

Thanks frodoman & bdreed35!
Avatar of mrong

ASKER

frodoman & bdreed35,

I am gonna spit the points as following coz you are trying to help me out here.
frodoman(30) bdreed(20)

Please let me know if you have any comments.
Thanks.
Thanks for the points.  I'm really not sure where the original problem was but as long as you've got it working...