Full Version: datasheet row colour based on a certain condition
UtterAccess Forums > Microsoft® Access > Access Forms
I am trying to find out if it is possible to modify a datasheet row background colour based on a certain condition
in the related query. Or at least one of the fields background colour.
Hope it is possible! :-)
here is a method I use to hightlight the current record in a continuous form. You can change the conditions for something else
ighlight Current Record, Customize Form Design Toolbar


make the following textbox controls in the detail section of your form:

name --> Me.RecordID_current
visible --> no

name --> HighlightBox
left --> 0
top --> 0
width --> width of detail section
height --> height of detail section, like 0.2
enabled --> false
locked --> true
tabstop --> false

send this control to the back*

in the design view of the form, select HighlightBox
you may need to use the object drop-down -- 1st icon on the formatting toolbar since it is behind everything)

conditional formatting
condition 1 --> Expression Is
--> [RecordID] = [RecordID_current]
change fill/back color to LIGHT YELLOW
For whatever color you want for your highlight

If my detail section background is White, I like to use light yellow for a highlight

RecordID is the name of your ID field control

then, in the form OnCurrent event, assign a value to the unbound RecordID_current
being unbound, it will have the same value on every record

Private Sub Form_Current()
   Me.RecordID_current = IIf([NewRecord], 0, [RecordID])
End Sub


when you are in the design view of a form, RIGHT-CLICK in a gray area to the right of your menu bar or an icon bar

choose "Customize" from the shortcut menu

in the dialog box...
choose the Commands tab

Category --> Form/Report Design

slide these icons to the Form Design toolbar:
(they are located about 3 "screens" down in the Commands list)

Align Right -- must have >1 control selected to be enabled
Align Left -- "
Align Top -- "
Align Bottom -- "
Bring To Front
Send To Back

If you don't know what these icons do, while the customize window is open, click on the DESCRIPTION command button for each one to see what is does.

to be efficient, the Align button are a MUST for form and report design
the Bring To Front and Send To Back are nice to have too -- since everything is "layered" and this gives you control on the order
since you are using a datasheet and not a continuous form, you will not be able to use a highlight box control -- you will have to set up the conditions for each of the fields you want the color to change for.
Oprefer to use continuous forms rather than the datasheet view, you have more control.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.