全部显示

DatasheetBackColor 属性

       

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

expression.DatasheetBackColor

expression   必需。返回“Applies To”列表中的一个对象的表达式。

说明

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

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

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

下表包含在 DAO Properties 集合中不存在的属性。除非使用了“格式”(数据表)工具栏设置它们,或者使用 CreateProperty 方法将它们添加到 Access 数据库 (.mdb) 并将其追加到 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