Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to keep leading zeros in Crystal Report

Posted on 2004-04-07
16
Medium Priority
?
1,037 Views
Last Modified: 2012-06-22
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
Comment
Question by:mrong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
  • 2
16 Comments
 
LVL 42

Expert Comment

by:frodoman
ID: 10774625
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
 

Author Comment

by:mrong
ID: 10774689
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
 
LVL 28

Expert Comment

by:bdreed35
ID: 10774693
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 42

Expert Comment

by:frodoman
ID: 10774733
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
 
LVL 28

Assisted Solution

by:bdreed35
bdreed35 earned 80 total points
ID: 10774795
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
 

Author Comment

by:mrong
ID: 10775048
frodoman,

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

Author Comment

by:mrong
ID: 10775065
Same output by using bdreed35's formula.
0
 
LVL 42

Expert Comment

by:frodoman
ID: 10775109
If you put just the field itself {Project.ProjectID} on the report what do you see in this example?  23?  2.3?
0
 

Author Comment

by:mrong
ID: 10775129
I see '23' if I put {Project.ProjectID} itself.
I see '3.0' if I use your formula.

Thanks.
0
 
LVL 42

Accepted Solution

by:
frodoman earned 120 total points
ID: 10775161
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
 

Author Comment

by:mrong
ID: 10775220
what do you mean by dropdown?
Thanks.
0
 
LVL 42

Expert Comment

by:frodoman
ID: 10775238
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
 

Author Comment

by:mrong
ID: 10775241
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
 

Author Comment

by:mrong
ID: 10775354
I got it. it shoud be
ToText ({table.field},"000000")

Thanks frodoman & bdreed35!
0
 

Author Comment

by:mrong
ID: 10775459
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
 
LVL 42

Expert Comment

by:frodoman
ID: 10775684
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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question