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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change textbox background color based on combobox selection 1

Status
Not open for further replies.

bill1856

Programmer
Sep 5, 2005
18
US
I have an employee tracking program in which I would like to have the background of the 'Name' textbox turn to yellow if the employee is under 18. I have a combobox where the user selects "18+" or "Under 18". I also need to (I think) requery on record change, so that when the user cycles through the records in the form, this background color is updated. Thanks for the help.
 
You have to store the combobox selection in a field for each record. In the AfterUpdate of whatever control holds this value you can assign the background color, and in the Form_Current sub place the same code, so that when you cycle thru the records the formatting will also be done. Alternatively, depending on your version of Access, you could use Conditional Formatting to do the same thing.

Private Sub Form_AfterUpdate()
If Me.Age.Value = "Under 18" Then
Me.Name.BackColor = vbYellow
Else
Me.Name.BackColor = vbWhite
End If
End Sub

Private Sub Form_Current()
If Me.Age.Value = "Under 18" Then
Me.Name.BackColor = vbYellow
Else
Me.Name.BackColor = vbWhite
End If

End Sub


The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Sorry to bother you again. Is there anyway to do something similar on a report?
 
Reports really aren't my forte, but I know that the Conditional Format is available for controls on reports. I guess , too, that it depends on what type of printer(s) you have access to; obviously changing a background color's not feasible if you only have B&W printer(s). You could always Bold your text for one condition, or have an asterik placed beside the name with a legend somewhere on the form that explains it. If I were you I'd post this question on the Access Report forum here.

Good Luck

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top