You can use the BackColor property to specify the color for the interior of a control (control: A graphical user interface object, such as a text box, check box, scroll bar, or command button, that lets users control the program. You use controls to display data or choices, perform an action, or make the user interface easier to read.) or section (section: A part of a form, report, or data access page such as a header, footer, or detail section.). Read/write Long.
expression Required. An expression that returns one of the objects in the Applies To list.
The BackColor property contains a numeric expression (numeric expression: Any expression that evaluates to a number. The expression can be any combination of variables, constants, functions, and operators.) that corresponds to the color used to fill a control's or section's interior.
You can use the Color Builder to set this property by clicking the Build button to the right of the property box in the property sheet (property sheet: A pane that is used to view or modify the properties of various objects such as tables, queries, fields, forms, reports, data access pages, and controls.). Using the Color Builder enables you to define custom back colors for controls or sections.
You can also set this property by using a control's or section's property sheet (property sheet: A pane that is used to view or modify the properties of various objects such as tables, queries, fields, forms, reports, data access pages, and controls.), a macro (macro: An action or set of actions that you can use to automate tasks.), or Visual Basic for Applications (VBA) (Visual Basic for Applications (VBA): A macro-language version of Microsoft Visual Basic that is used to program Microsoft Windows-based applications and is included with several Microsoft programs.) code, or by using the Fill Color command under Font (on the Design or Format tab, depending on whether you are in Design view or Layout view).
In Visual Basic for Applications (VBA) code, use a numeric expression to set this property. This property setting has a data type of Long (Long data type: A fundamental data type that holds large integers. A Long variable is stored as a 32-bit number ranging in value from -2,147,483,648 to 2,147,483,647.).
You can set the default for this property by using a control's default control style (default control style: The default property setting of a control type. You customize a control type before you create two or more similar controls to avoid customizing each control individually.) or the DefaultControl property in VBA code.
For Table objects you can set this property using the Fill Color command under Font on the Data tab, or in VBA code by using the DatasheetBackColor property.
To use the BackColor property, the BackStyle property, if available, must be set to Normal.
The following example uses the RGB
function to set the BorderColor
, and ForeColor
properties depending on the value of the
text box. You can also use the QBColor
function to set these properties. Putting the following code in the Form_Current( ) event sets the control display characteristics as soon as the user opens a form or moves to a new record.
Dim curAmntDue As Currency, lngBlack As Long
Dim lngRed As Long, lngYellow As Long, lngWhite As Long
If Not IsNull(Me!txtPastDue.Value) Then
curAmntDue = Me!txtPastDue.Value
lngRed = RGB(255, 0, 0)
lngBlack = RGB(0, 0, 0)
lngYellow = RGB(255, 255, 0)
lngWhite = RGB(255, 255, 255)
If curAmntDue > 100 Then
Me!txtPastDue.BorderColor = lngRed
Me!txtPastDue.ForeColor = lngRed
Me!txtPastDue. = lngYellow
Me!txtPastDue.BorderColor = lngBlack
Me!txtPastDue.ForeColor = lngBlack
Me!txtPastDue. = lngWhite