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

Set Colors in Forms and Reports

How to

Set Colors in Forms and Reports

by  randysmid  Posted    (Edited  )
Setting colors in forms and reports

You can use the RGB function to set colors in forms and reports by using the "forecolor" and "backcolor" properties in VBA code. These colors can be conditional based on some field value. The RGB function uses the three primary colors of red, green, and blue (in that order). By adjusting the numbers, you can get up to 16 million color combinations.

As you probably know, "forecolor" is the color of the text in a textbox. You can use the "backcolor" to set the background color of a form, a report, or just about any object.

Here are some samples:
txtSales.ForeColor = RGB(255, 0, 0) 'color is red
frmStartup.BackColor = RGB(125, 125, 0) 'gray

If txtAccountBalance > 0 then
txtAccountBalance.ForeColor = RGB(0, 255, 0) 'green
End if

lblReportTitle.ForeColor = RGB(0, 0, 255) 'blue
txtUserName.ForeColor = RGB(0, 0, 0) 'black
rptMaster.BackColor = RGB(255, 255, 255) 'white
?.ForeColor = RGB(255, 125, 0) 'orange
?.ForeColor = RGB(255, 255, 0) 'yellow
?.ForeColor = RGB(255, 0, 255) 'purple
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