• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1077
  • Last Modified:

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.
0
mrong
Asked:
mrong
  • 8
  • 6
  • 2
2 Solutions
 
frodomanCommented:
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).


0
 
mrongAuthor Commented:
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.
0
 
bdreed35Commented:
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.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
frodomanCommented:
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.
0
 
bdreed35Commented:
To get frodoman's formula to work, you need to convert your Project ID to a string.

You can do this a couple of different ways.

You can try changing the "+" sign to "&" like this:

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

   or

explicitly convert it to a string before concatenating it:

Right('0000' + cstr({Project.ProjectID}),4)
0
 
mrongAuthor Commented:
frodoman,

Your formula didn't give me the right data->'3.0' instead of '0023'.
I am trying bdreed35's formula.
0
 
mrongAuthor Commented:
Same output by using bdreed35's formula.
0
 
frodomanCommented:
If you put just the field itself {Project.ProjectID} on the report what do you see in this example?  23?  2.3?
0
 
mrongAuthor Commented:
I see '23' if I put {Project.ProjectID} itself.
I see '3.0' if I use your formula.

Thanks.
0
 
frodomanCommented:
Make sure your dropdown on Crystal is set to "Crystal Syntax" and not to vb syntax.

Use this formula: right("0000"&23,4)    and make sure you see '0023'

Then change it to this:  right("0000"&{Project.ProjectID},4) and let me know if it's still wrong.
0
 
mrongAuthor Commented:
what do you mean by dropdown?
Thanks.
0
 
frodomanCommented:
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.
0
 
mrongAuthor Commented:
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.
0
 
mrongAuthor Commented:
I got it. it shoud be
ToText ({table.field},"000000")

Thanks frodoman & bdreed35!
0
 
mrongAuthor Commented:
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.
0
 
frodomanCommented:
Thanks for the points.  I'm really not sure where the original problem was but as long as you've got it working...
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 8
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now