Highlight the current record on an Access form showing multiple records with a yellow background color. To make this happen, use Conditional Formatting, a control to keep track of the primary key value, and a little VBA.
Create a textbox control named txtHighlight that is positioned behind all the other controls. This will be the control that changes color to highlight the active record.
If you are using a datasheet form instead of a continuous form, you can't have a control under all the others, so set the conditional formatting rule on every control. You can then select all the textboxes and set the rule.
Create a control named CurrentID to keep track of the primary key. On the form Current event, which happens when a record changes, set CurrentID to the primary key. If you are on a new record, set it to be 0 (zero).
If the data is in Access (as opposed to SQL server or another back end), Autonumbers are assigned as soon as any field gets a value. Therefore, on new record, force the user to enter particular data first. On the AfterUpdate event of the required control, set the value in the control that tracks the primary key value.
Learn about form events like Current, which happens when the record is changed, and the Dirty event which happens when data begins getting changed; and control events such as Got Focus, BeforeUpdate, AfterUpdate.
Also learn how to record date/time records were changed, and how to drop a list for a combo box if it needs to be filled when the user clicks ANYWHERE in the control or tabs into it.
To specify code for an event:
1. select the object you want such as the form or a control
2. go to the Event tab of the property sheet
3. choose [Event Procedure] or pick it from the list -- or just type "[" to pick [Event Procedure]
4. Click the builder button [...], or press Ctrl+F2, to go to the Visual Basic Editor
5. Access will automatically create the Sub declaration and End Sub Statements.
6. Type what you want to happen between the procedure declaration and End statements.
Thanks for watching, and using Microsoft Access!
have an awesome day,