DatasheetBackColor 属性

expandtri全部显示

可以在 Visual Basic 中使用 DatasheetBackColor 属性,指定或确定在Microsoft Access 数据库 (.mdb) 的“数据表”视图中的整个查询窗体的背景色。Long 型,可读/写。

expression.DatasheetBackColor

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

说明

DatasheetBackColor 属性是代表数据表的背景色和前景色设置的 Long Integer 值。

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

?也可以通过单击“格式”(数据表)工具栏上的“填充/背景色”并单击调色板上的相应颜色来设置该属性。

 

?也可以通过使用“选项”对话框的“数据表”选项卡设置 DatasheetBackColor 属性,方法是单击“工具”菜单上的“选项”。

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

下表包含了 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