473,465 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Conditional Formatting Access 2007 - Reports

3 New Member
I'm putting together a report (a very simple one) where I'm grouping by crime type (all, violent, property), displaying city and district data with percent change. I need to format the field background color based on crime type (i.e. pale red for violent, pale green for property, pale purple for all) and also want to format the text in the percent change field to be red if positive (crime went up) or blue if negative (crime went down).

I can do either or through the conditional formatting button, but I can't figure out how to do both. I'm hoping I'm missing the obvious as I'm not an access guru (I'm a statistican - making things pretty is not my usual bag, but someone handed me an excel report with the conditional formatting and asked me to automate it). thanks in advance for any and all help!
Mar 9 '12 #1
13 8419
NeoPa
32,556 Recognized Expert Moderator MVP
I don't get the problem Liz. One control has one setup using Conditional Formatting, and the other control has a separate one that also uses Conditional Formatting. Where's the problem?
Mar 9 '12 #2
liztowne
3 New Member
Sorry for not being clear - I'm formatting all the fields in the report row to have the same background color based on crime type and want the font in the 28d % field to also format based on being negative or positive.

Crime Area 28d %
All City -12.3%
Violent City 8.2%
Property City -18.4%

So the above would be purple across the first row, with -12.3% in blue font, pale red on the second row with 8.2% in red font and green on the last row with -18.4% in blue font.

If there were 6 options for the conditional formatting section it would be fine. I'm fairly sure I need to code it, but I can't figure out where/how. I'm decent in programming in other languages/packages, but just don't have much familiarity with access/sql/vba.
Mar 10 '12 #3
NeoPa
32,556 Recognized Expert Moderator MVP
I'm afraid that three options is the limit with Conditional Formatting Liz :-(

If you need to apply logic to differentiate between six separate conditions then I'm afraid even good coding skills won't help, as the scope just isn't there.
Mar 10 '12 #4
Stewart Ross
2,545 Recognized Expert Moderator Specialist
@liztowne, what version of Access are you using? A2007/2010 can apply more than three conditions when using conditional formatting, but A2003/2000 cannot as NeoPa said.

If you are unable to use conditional formatting to achieve the effect you want, it should also be possible to change the font colour for a control dynamically in VBA code in response to the On Format event of the report's Detail section.

If you take the VBA approach to working with font colours outside of the ones for which pre-defined constants are available (which I think will be the case for the colour shades you are mentioning) you would need to note down the numeric values of the colours concerned before you start to write the VBA code. The numeric values are shown in the property settings for the control concerned after you apply a colour change in design view, say.

One other approach you may want to consider is to overlay two textbox controls, the one on top being the control for the text itself which you can conditionally format and the other being an unbound control that you can set the background colour of using a separate conditional format. With one overlaid on the other you may be able to achieve the combined effect you are mentioning with no VBA programming at all. The top control would need to be set to have transparent background, of course, to allow the fill from the one below to show through.

-Stewart
Mar 10 '12 #5
NeoPa
32,556 Recognized Expert Moderator MVP
Very interesting Stewart. Are you saying that there is actually a way to effect the properties of controls on continuous forms/reports if you apply the changes in the Format event procedure?

In such circumstances, would there be any exposure to a user saving the form if they're allowed to (Many do, as you know, by pressing Ctrl-S when actually intending to save the current record.)?
Mar 10 '12 #6
Stewart Ross
2,545 Recognized Expert Moderator Specialist
@NeoPa, the attached PDF files show the two techniques in use together. This is a sample based on the Catalog report of the Northwind database.

The attachment called Catalog Formatted.pdf shows the use of conditional formatting on the ProductID control (changing the text colour to Red in this case when the product ID is greater than 40). It also shows the use of a textbox underlying transparent controls whose background colour is set in the On Format event of the detail section to green when ProductID is greater than 60 and to white otherwise.

The On Format event code is just:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  2.     If Me.ProductID > 60 Then
  3.         Me.txtBGD.BackColor = &H22B14C
  4.     Else
  5.         Me.txtBGD.BackColor = &HFFFFFF
  6.     End If
  7. End Sub
For test purposes I did not use descriptive constants for the hex colour values shown, which I would normally have done.

The attachment simply called Catalog.pdf shows the original version of page 5 of the report for comparison.

I tested saving the report in print preview mode by pressing Ctrl-S and the design values for the controls concerned were unchanged.
Attached Files
File Type: pdf Catalog.pdf (11.0 KB, 597 views)
File Type: pdf Catalog Formatted.pdf (11.1 KB, 615 views)
Mar 10 '12 #7
NeoPa
32,556 Recognized Expert Moderator MVP
Nice Stewart. Thanks for this.

Do you happen to know if this technique works in Access 2003 and earlier too, or is it only a 2007+ facility?
Mar 11 '12 #8
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Works in A2003/2000 as well, NeoPa.

-S
Mar 11 '12 #9
NeoPa
32,556 Recognized Expert Moderator MVP
Excellent Stewart.

It looks like I'll have to provide an addendum to my article (Why Values in Unbound Form Controls do not Persist) though ;-)
Mar 11 '12 #10
liztowne
3 New Member
Thanks Stewart! That is exactly what I was looking for - both solutions worked for me. I thought there might be a way to hard code the text changes in VBA, but wasn't sure where to do the change at. One of these days I'll get serious about learning VBA in Access and not use such an ad-hoc approach :)

Thanks also to Neo-Pa for quick and helpful feedback as well (including clarifications from Stewart).
Mar 12 '12 #11
NeoPa
32,556 Recognized Expert Moderator MVP
You're welcome Liz.

Actually, I also learned something important in this thread. One of the best thing about volunteering time for this site is that one is surrounded by so many very expert programmers and database designers. I love it :-)

PS. It only works for reports, which is a bit of a blow for the concept as a whole, but is fine and very handy for working on reports. I've added the addendum now if anyone would like to check the linked article again (Why Values in Unbound Form Controls do not Persist).
Mar 12 '12 #12
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Excellent example in your addendum to the linked article, NeoPa - the varying shades associated with the scores shown work very well.

As you rightly point out, this technique works best for reports, which are quite different to forms in their approach to preparing individual rows for display on a page.

Although it is perfectly possible to use similar programmed approaches with single-view forms to change font and background colours this does not work for continuous forms - as the change will be replicated to all rows visible on the form simultaneously, not just the currently-active row. Forms in datasheet view are also unsuitable for this approach.

-Stewart
Mar 12 '12 #13
NeoPa
32,556 Recognized Expert Moderator MVP
Thanks Stewart. I greatly appreciate your comments :-)

As for Datasheet view, many of the properties for the controls don't work in those at all. Mainly because they aren't actually used if I understand it correctly. It uses the fields directly I believe, though I don't use that option myself so I'm no expert.
Mar 12 '12 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: slinky | last post by:
Thanks in advance... I have a continuous style form with a field for each record called "STATUS". I simply want to have the form load and if the value of the textbox is "Inactive" I want the...
1
by: sptadmin | last post by:
In Access 2007 Reports I have totaled multiple columns but cannot figure out how to total those columns - does anyone know how to do this? My report consists of data from various months and now...
3
by: LostBoy | last post by:
Hi All, I have a couple Date fields in a form that are usually Null but when they are not I would like the field to be highlighted, bold and flash. I usually right click on the field and go to...
1
by: sjivanjee | last post by:
Help In Access 2007 - Report (Grouping and Sub Totaling) I have two table one stores student information and other one is for their attendance. In the attendance table their is a field called...
8
by: DanicaDear | last post by:
I have something interesting...looking to see if anyone else has came across this. I have a query with parameter and and the query works beautifully every time. However, when I use the wizard...
0
by: accessles | last post by:
I have a 3 page report where page 3 prints the header but there are no details. Is there a way in vba to accomplish this. The report is based on a query and page 3 has no records printed in the...
2
by: mfuentes74 | last post by:
Hi! I need help I have a report in Access 2007 and I need to insert a page break after every operator id (kn028mf) the first five characters are the same only the last two change, I have tired...
3
by: gershwyn | last post by:
I have a report that summarizes the costs for various projects, based off a query called ProjectCosts (outlined below.) The report is grouped first by companyNumber, then by branch. Branch can be...
0
by: sarah2855 | last post by:
Hello, I would like to insert a pivot table in an access report.I was able to create a pivot table chart in Query -> pivot table view but I don't know how to incorporate that in reports. Is this...
2
by: ghiey | last post by:
hi to all, i have searched for a solution regarding exporting access 2007 reports to excel file. i have converted to access 2007 my database from access 2003. i guess microsoft omitted the ease...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.