Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting a field in a report 2

Status
Not open for further replies.

CondorMan

Technical User
Jan 23, 2005
211
0
0
GB
I use Access 2003 and have come across a formatting problem in a report.

I have fields [Country] and [Population]. I created new fields [=Sum([Population])] and [=Count([Population})] which I named SumPopulation and CountPopulation.

For each country, I want to have the report print:

The population of XXX is YYY and this is ZZZ% of the total.

so I've tried:

="The population of " & [Country] & " is " & [Population] & " and this is " & ([Population]/[SumPopulation]) & " of the total."

The problem that I have is that I can't make the ([Population]/[SumPopulation]) retain a percentage format. It reverts to decimal. Even if I calculate the percentage and use a hidden field (such as a field called [Percentage] which I format correctly), the formatting isn't retained when I add it to the string that I want to print.

I hope this makes sense! Is there any way to do what I want?
 
Try

="The population of " & [Country] & " is " & [Population] & " and this is " & format([Population]/[SumPopulation], "Percent") & " of the total."

ChaZ

There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.
 
That's great, thank you.

I see that the format can be changed to others (i.e. long date etc.), and the percentage is displayed with 2 decimal places. I've tried to get only one decimal place by ... "Percent,1") and ... "Percent",1) but neither works. I've tried googling (access 2003 + format + field) but it just brings up the more usual "normal" formatting process. Is there a specific name for this type of formatting (i.e. a google "buzz phrase") that will bring up details that I want?
 
Well, there probaly is a simple solution, but using a little string function stuff, I think you can make it work with one decimal.

Maybe - left (format (yournumber, "percentage"), len (format (yournumber, "percentage") -1)



There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.
 
Have you tried this ?
Format([Population]/[SumPopulation], "0.0%")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Perfect - thank you. That got me out of a bit of a hole!
 
I told you there was a simple solution!

ChaZ

There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.
 
LOL. Thanks for your input. It looks like we've both learned something!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top