Form.DatasheetForeColor 属性 (Access)

使用 Visual Basic 中的 DatasheetForeColor 属性可以指定或确定 Access 数据库中数据表视图中表、查询或窗体中所有文本的颜色。 读/写 Long

语法

表达式DatasheetForeColor

expression:表示 Form 对象的变量。

备注

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

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

属性 属性继续
DatasheetBackColor DatasheetFontUnderline *
DatasheetCellsEffect DatasheetFontWeight *
DatasheetFontHeight * DatasheetForeColor *
DatasheetFontItalic * DatasheetGridlinesBehavior
DatasheetFontName * DatasheetGridlinesColor

注意

添加或设置以星号列出的任何属性时,Access 会自动将其添加到 Properties 集合。

示例

以下示例使用 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 支持和反馈,获取有关如何接收支持和提供反馈的指南。