Link to home
Start Free TrialLog in
Avatar of CJSilver
CJSilverFlag for United States of America

asked on

Highlight row in Access 2007

I am trying to highlight a row in Access 2007. I have a checkbox in the row, if the checkbox is checked, then I want the row highlighted. I saw a post a few months back by Capricorn1 that clearly shows how to do this using conditional formatting. But for some reason it isn't working. Here is how my report and conditional formatting is setup.
User generated image
I was reading Microsoft's help file on conditional formatting and found the following:

4.On the All tab of the property sheet, if the first two properties (Name and Control Source) are identical, or if the Name property matches another field name in the form's or report's underlying record source, edit the Name property so that it is unique. A common practice is to add a short prefix to the name. For example, if the control is a text box, you might add the prefix "txt" to its Name property, as in "txtQuantity."

This seems strange to me, by default the name and control are the same on all my fields. SO I added a space between words to make the name and control different. So the control for the checkbox field is OnHold and the name is On Hold. But it still doesn't work. And now one of my fields "TotalHours" now opens a "Enter Parameter Value" window, even though I didn't change the control only the name, the control is Total Hours and the name is TotalHours. I hit enter, leaving the parameter blank and the report runs and the field populates, but I obviously do not want this window opening every time.

I have the checkbox formatted yes/no, though I have also tried in the conditional formatting [OnHold]=1, [OnHold]=ON, [OnHold]="Yes", none of these have worked. If I only click on the OnHold control and change the condition to Field Value is equal to Yes, then it does highlight that one field. But I cannot get the entire row to highlight, or get anything to highlight by using "Expression is" as a condition.

Any help would be greatly appreciated.
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

A common solution is that the "BackStyle" property of the control must be set to Normal, for the Condition formatting to work...
see this simple attached sample...

If you highlight (select) both the LastName and Title Controls, (in design view) you will see that they both have the same Conditional Formatting, yet the Backstyle is set to Normal for  Last Name and "Transparent for Title...

;-)

JeffCoachman
Database114.mdb
Avatar of CJSilver

ASKER

Jeff,

I checked all of the controls in the detail section and the back style is normal for all of them.
In a report, a method that I find is quite useful for doing this is to use the Detail sections Format event.  Something like:

Private Sub Detail_Format

    me.detail.backcolor = iif(me.chkFieldName, rgb(255,0,0), rgb(0, 255, 0)

End Sub
Upload a working model showing the issue.
Tell what to do and expect what.
Dale,

I want to highlight the row when the OnHold field = Yes. How do I show this in your code?

hnasr,

I cannot upload my data and do not have time to create new tables that have bogus data.
The following example would highlight those records where the value of the [OnHold] field <> 0.  I use that syntax, because various databases use different values for Yes (some use 1, some use -1, some use any value other than zero).

Private Sub Detail_Format

    me.detail.backcolor = iif(me.[OnHold] <> 0, rgb(255,0,0), rgb(0, 0, 0)

End Sub
Dale,

I put in the code as you show except you are missing a parenthesis. I have:

Private Sub Detail_Format()

Me.Detail.BackColor = IIf(Me.[OnHold] <> 0, RGB(255, 0, 0), RGB(0, 0, 0))

End Sub


But it is still not working, I get no change in color.
CJSilver ,

Again, the term "highlight the row" is a bit vague.
What you appear to be trying to do is highlight the *controls* in the row, ...not the row itself.

Enter fyed's post...
I do this too instead.
This way, there is only ONE object to format.
The draw back might be that this will not work if the report is opened in "Report View"
...but this is the way I would go, ...I am sure Dale can get you going on this technique...
;-)

Jeff
SOLUTION
Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Jeff,

You mentioned that it will not work in Report View? I need to be able to see the highlight on the screen. What view can I see it?
Yeah I tried to CF multiple controls and I had trouble as well...
I saw this:
http://www.utteraccess.com/forum/Conditional-Formatting-t1546463.html

Funny but I could do two controls, but 3 gave me trouble...
Curios to see if other experts can confirm (Access 2007)
Good catch Jeff.  I never use Report view, I always use PrintPreview.
Jeff,

I get the following error when I run your code:

User generated image
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
CJSilver,

Remember to put our code on the Detail Format event....
I have it working now. It erred on

Private Sub Detail_Format()

I deleted it and let Access recreate it as:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

and now it works, I needed to change the controls to transparent also. The only issue is I can't see it in Report view, as Jeff mentioned above. But I can deal with that. Thank you both, I am going to split the points between you.
<Good catch Jeff.  I never use Report view, I always use PrintPreview.>
;-)
Me too...

Don't get me started...

Why is Report View the default view?
Why can't you Globally change this to make Print Preview the default for all New Reports?

I fully understand the "Benefits" of Report View:
Interaction (Click Button, Follow Hyperlinks...)
Quick Viewing
Filtering
RefreshAll
Find
...etc

But, ...the drawbacks...
Poor graphics
No Page Breaks
No accurate Page Numbers
No Format Code will run
No quick Access to the Page setup Options...
...et al

I mean, you know how I love my report automation...
;-)

Jeff
Thanks but my code was just a simple mod of Dale's code/suggestion.
(besides, it did not work anyway...)
:-(

Pretty simple, no real effort taken on my part...

If you want to request that all the points be given to Dale, I have no problem with that...

;-)

Jeff
don't sweat it, CJ.  No need to reallocate points.