Conditional Formatting vs. Code for Highlighting/backcolor questio

  • Thread starter Thread starter ThriftyFinanceGirl
  • Start date Start date
Haven't played with that, but try using the .BackColor property as in...

[Forms]![FormName]![DetailSectionName].BackColor

or

[Forms]![FormName]![SubFormName].subform![DetailSectionName].BackColor

The Header, Detail, and Footer sections of a form are controls just like any
other. Typically, the .Name property will default to 'Header', 'Detail',
'Footer'.

If that doesn't work, you can add an unbound field that covers the entire
detail section and add Conditional Formatting to that. Just be certain that
you ensure that it isn't set as a TabStop. You'll may also want to add code
to its onGotFocus event to move the cursor to an actual field as a cosmetic
touch to avoid the user's complaining about 'Where's the cursor'.

[Forms]![FormName]![DestinationControlName].SetFocus
 
Need to be a little more specific.

What version of Access are you using? If A2007, then the details section of
both reports and forms contain a "Alternate Back Color" property. Just set
the color of this property to achieve your goal.

If you are using an earlier version of Access, it becomes a little more
difficult (at least I don't remember earlier versions containing this
property). If you have a field in your forms RecordSource (table or query)
which contains a sequential numeric value (you could call this a row number),
then you could:
1. Create an unbound textbox and size it to span the entire width and
height of the detail section.
2. You will then have to move it to the background (I think 2003 has this
ability) by right clicking on the textbox and selecting - Position -> Send to
Back from the popup menu. You may also have to select each of the other
controls and bring them to the front.
3. Then set its Tab Stop property to No
4. In the controls GotFocus event, set the focus to one of the other
controls in the details section of the form.
5. Finally, set the conditional formatting for that text box so that the
condition is based on an expression. The expression will look something like:

Same technique will work for a report, although you won't have to do steps 3
and 4 in a report. Another method in a report would be to use the Format
event of the detail section. Add the following code to that event to get
alternate color backgrounds.


Static RowCount As Long

RowCount = RowCount + 1
Me.Section(acDetail).BackColor = IIf(RowCount Mod 2 = 0, RGB(255, 255,
255), RGB(236, 250, 252))
 
ThriftyFinanceGirl said:
How can I get an entire row to highlight instead of just one field?

A single row in a form? Can't be done for a form in
datasheet view.

For a continuous form, use a large text box as Dale
described. An alternative to Dale's steps 2, 3 and 4 is to
set the large text box's Locked property to Yes and Enabled
property to No.
 
Using 2003, they haven't upgraded here yet. However, I think I can use the
box in the background. However, using conditional formatting you can set a
field that has focus in a datasheet a certain backcolor. Then you could set
the other fields with a conditional formatting also? But it would have to be
an expression. I guess that is what you guys are all saying can't be done?
 
I would use an expression for the background color.

You don't want the unbound control to get the focus, that is the reason for
the code in the GotFocus event. Marshall's idea of disabling the control is
really a pretty good one. You could give the set the controls backcolor
using conditional formatting, and then when you disable it, that will make it
a little duller color. But overall a pretty good idea.

The challenge will be the sequentially numbered field. Autonumber fields do
not guarantee that they will be generated sequentially, and even if they did,
that doesn't account for records that get deleted. So in order for this
method to work, you will need to add another field (long integer) to your
underlying recordset which you could update before opening the form, OR, you
would have to add a column to your record sources query, something like:

SeqNumber: (SELECT Count(*) FROM yourTable as T WHERE T.[PKField] < =
yourTable.[PKField])

The problem with either of these is that they could be time consuming, and
neither one will work if you filter the form after loading the recordset.
 
Back
Top