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 to highlight the selected record in a continuous form

Access Howto:

How to highlight the selected record in a continuous form

by  Frink  Posted    (Edited  )
Hallo,

This FAQ explains how to highlight the selected record of a continuous form by changing the background colour of the current record. This has only been tested in Access '97. In later versions of access you can use Conditional Formatting to acieve this highlighting.

Firstly I'll assume your form is based on a table with a primary key of lngId.

Create a text field control txtBackground to the size of your whole record, and send it to the back of the form.
Make the font WebDings and the forecolor the 'selected' colour you want. Make the background colour the 'unselected' colour.

Make the background colour of all your controls in the record as the selected colour, but make them all transparent.

Create a new text control called txtCurrentRecord and put it in the form header or footer. You can make this invisible once you've checked that it works.
In the OnCurrent Event procedure, put:
Code:
Me!txtCurrentRecord = Me!lngId

Set the Control Source of txtBackground:
Code:
=IIf([lngId]=[txtCurrentRecord],String$(10,"g"),"")

This field will be empty unless the record you're on is the current record, in which case it would be a string of 10 WebDings g characters, which happen to be a solid block.

If the coloured bar is not tall enough then increase the font size in txtBackground.
If the coloured bar is too narrow then increase the '10' in the Control Source.

Hope that makes your forms prettier,

- Frink

Note: SturdyErde has (rightly) pointed out that this will not work for new records where lngId is an autonumber as these are not populated until the record is saved.
He suggests adding an Or IsNull statement to the IIf statement. I no longer have Access '97 so am unable to test this
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