Access) (Form.DatasheetBackColor 属性

使用 Visual Basic 中的 DatasheetBackColor 属性指定或确定 Microsoft Access 数据库中数据表视图中整个表、查询或窗体的背景色。 读/写 Long。

语法

表达式。DatasheetBackColor

expression:表示 Form 对象的变量。

备注

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

设置 DatasheetBackColor 属性的表或查询不会影响该属性设置对于用作其数据源的表或查询的窗体。

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

注意

使用星号添加或设置任何属性时,Access 会自动将其添加到 “属性” 集合。

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

示例

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

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

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。