DatasheetForeColor 属性

expandtri全部显示

使用 Visual Basic 中的 DatasheetForeColor 属性可以指定或确定在 Access 数据库 (.mdb) 的“数据表”视图中,表、查询或窗体中的所有文字的颜色。Long 型,可读/写。

expression.DatasheetForeColor

expression     必需。返回“应用于”列表中的一个对象的表达式。

说明

以下设置信息应用于 Microsoft Access 数据库和 Access 项目 (.adp):

?可以通过在“格式(数据表)”工具栏上单击“字体/前景色”并在调色板中单击所需的颜色,设置该属性。

 

?可以通过在“工具”菜单上单击“选项”,使用“选项”对话框的“数据表”选项卡,设置默认的 DatasheetForeColor 属性。

说明

设置表或查询的 DatasheetForeColor 属性不会影响使用该表或查询作为数据源的窗体的该属性。

下表包含了 DAO Properties 集合中的部分属性,这些属性在用户使用“格式(数据表)”工具栏来对其进行设置,或使用 CreateProperty 方法在 Access 数据库中添加这些属性并将其追加到 DAO Properties 集合中之前不存在。

DatasheetBackColor

DatasheetFontUnderline*

DatasheetCellsEffect

DatasheetFontWeight*

DatasheetFontHeight*

DatasheetForeColor*

DatasheetFontItalic*

DatasheetGridlinesBehavior

DatasheetFontName*

DatasheetGridlinesColor

 

注释   当添加或设置任何带有星号的属性时,Microsoft Access 会自动将它添加到 Properties 集合中。

示例

以下示例使用 SetTableProperty 过程将表的字体颜色设置为深蓝,背景色设置为浅灰色。如果设置属性时出现“找不到属性”错误,可以用 CreateProperty 方法将属性添加到对象的 Properties 集合中。

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