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!

How and why to code Access Reports

How to

How and why to code Access Reports

by  munger  Posted    (Edited  )
I live in a non-English speaking country and my workplace has technicions that speak English and managers that speak the local language. So when I program in Access I always have to fix the reports so the managers will understand. Access reports, even though they appear like FORMS in DESIGN view, they are quite different.

Even you English-folks out there could have good reason to use codes in Access reports. One example:

You use a form with a check box whose field is "Breakable". That field in the underlying table is a yes/no field. If you use the report wizard to make a report out of that form and you want to group on the "Breakable", so the report is divided into Breakable YES and Breakable NO. Wouldn't it be better to have "Fragile" and "NonFragile" appear in your report? How do you do that? By code. Where does the code need to be? Do a right-click on the "DETAIL" section of the report>click "BUILD">click "CODE". Take my advise: DO NOT CODE ANYWHERE ELSE when fiddling with reports.

There is something unusual about coding reports: You can not mention fields in the code that do not have a textbox or check box in the DETAILS section. Don't ask me why. So if you need a field, place a text box bound to that field in the DETAILS secttion and make it small and invisible. Now your code will work.

Now back to our example ("Breakable Yes"="Fragile"):

Put an unbound textbox in the DETAIL section and call it txtFragile

Code like this:
if [Breakable]=true then
txtFragile="FRAGILE"
else
txtFragile="NON-FRAGILE"
end if

Now make the checkbox invisible. Do not delete it or your code will not work!

Of course, fiddle with the unbound textbox to place it properly on the report.

Good Luck.

munger@netvision.net.il
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top