DatasheetBackColor, DatasheetForeColor Properties

Applies To   Form object, QueryDef object, TableDef object.

Description

Setting

The DatasheetBackColor and DatasheetForeColor properties are a Long Integer value representing the background color and font color setting for a datasheet.

You can also set these properties by clicking the Fill/BackColor button or the Font/ForeColor button on the Formatting (Datasheet) toolbar and clicking the desired color displayed on the color palette.

You can also set the default DatasheetBackColor and DatasheetForeColor properties by using the Datasheet tab of the Options dialog box, available by clicking Options on the Tools menu.

Remarks

Setting the DatasheetBackColor or DatasheetForeColor properties for a table or query won't affect these property settings for a form that uses the table or query as its source of data.

The following list contains the properties that don't exist in the Properties collection for TableDef or QueryDef objects until you add them by using the CreateProperty method or set them by using the Formatting (Datasheet) toolbar.

  • DatasheetBackColor
  • DatasheetCellsEffect
  • DatasheetFontHeight*
  • DatasheetFontItalic*
  • DatasheetFontName*
  • DatasheetFontUnderline*
  • DatasheetFontWeight *
  • DatasheetForeColor*
  • DatasheetGridlinesBehavior
  • DatasheetGridlinesColor

Note When you add or set any property listed with an asterisk, Microsoft Access automatically adds it to the Properties collection.

See Also   BackColor property, DatasheetCellsEffect property, DatasheetFontItalic, DatasheetFontUnderline properties, DatasheetFontName, DatasheetFontHeight properties, DatasheetFontWeight property, DatasheetGridlinesBehavior property, DatasheetGridlinesColor property, ForeColor property.

Example

The following example uses the SetTableProperty procedure to set a table's font color to dark blue and its background color to light gray. If a "Property not found" error occurs when the property is set, the CreateProperty method is used to add the property to the object's Properties collection.

Dim dbs As Database, tdfProducts As TableDef
Const lngForeColor As Long = 8388608        ' Dark blue.
Const lngBackColor As Long = 12632256        ' Light gray.

Set dbs = CurrentDb
Set tdfProducts = dbs!Products
SetTableProperty tdfProducts, "DatasheetBackColor", dbLong, lngBackColor
SetTableProperty tdfProducts, "DatasheetForeColor", dbLong, lngForeColor

Sub SetTableProperty(tdfTableObj As TableDef, strPropertyName As String, _
        intPropertyType As Integer, varPropertyValue As Variant)
    Const conErrPropertyNotFound = 3270
    Dim prpProperty As Property
    On Error Resume Next                    ' Don't trap errors.
    tdfTableObj.Properties(strPropertyName) = varPropertyValue
    If Err <> 0 Then                        ' Error occurred when value set.
        If Err <> conErrPropertyNotFound Then
            ' Error is unknown.
            MsgBox "Couldn't set property '" & strPropertyName _
                & "' on table '" & tdfTableObj.Name & "'", vbExclamation, _
                Err.Description
            Err.Clear
        Else
            ' Error is "Property not found", so add it to collection.
            Set prpProperty = tdfTableObj.CreateProperty(strPropertyName, _
                intPropertyType, varPropertyValue)
            tdfTableObj.Properties.Append prpProperty
            Err.Clear
        End If
    End If
    tdfTableObj.Properties.Refresh
End Sub