Share via


DatasheetForeColor Property [Access 2003 VBA Language Reference]

You can use the DatasheetForeColor property in Visual Basic to specify or determine the color of all text in a table, query, or form in Datasheet view within an Access database (.mdb). Read/write Long.

expression.DatasheetForeColor

expression Required. An expression that returns one of the objects in the Applies To list.

Remarks

The following setting information applies to both Microsoft Access database and Access projects (.adp):

  • You can also set this property by clicking Font/ForeColor on the Formatting (Datasheet) toolbar and clicking the desired color displayed on the color palette.

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

Remarks

Setting the DatasheetForeColor property for a table or query won't affect this property setting for a form that uses the table or query as its source of data.

The following table contains the properties that don't exist in the DAO Properties collection of until you set them by using the Formatting (Datasheet) toolbar or you can add them in an Access database (.mdb) by using the CreateProperty method and append it to the DAO Properties collection.

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

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

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 Object, objProducts As Object
Const lngForeColor As Long = 8388608        ' Dark blue.
Const lngBackColor As Long = 12632256        ' Light gray.
Const DB_Long As Long = 4
Set dbs = CurrentDb
Set objProducts = dbs!Products
SetTableProperty objProducts, "DatasheetBackColor", DB_Long, lngBackColor
SetTableProperty objProducts, "DatasheetForeColor", DB_Long, lngForeColor

Sub SetTableProperty(objTableObj As Object, strPropertyName As String, _
        intPropertyType As Integer, varPropertyValue As Variant)
    Const conErrPropertyNotFound = 3270
    Dim prpProperty As Variant
    On Error Resume Next                ' Don't trap errors.
    objTableObj.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 = objTableObj.CreateProperty(strPropertyName, _
                intPropertyType, varPropertyValue)
            objTableObj.Properties.Append prpProperty
            Err.Clear
        End If
    End If
    objTableObj.Properties.Refresh
End Sub

Applies to | Form Object

See Also | DatasheetBackColor Property