使用 Visual Basic 中的 DatasheetForeColor 属性可以指定或确定在 Access 数据库 (.mdb) 的“数据表”视图中,表、查询或窗体中的所有文字的颜色。Long 型,可读/写。
expression.DatasheetForeColor
expression 必需。返回“Applies To”列表中的一个对象的表达式。
以下设置信息应用于 Microsoft Access 数据库和 Access 项目 (.adp):
设置表或查询的 DatasheetForeColor 属性不会影响使用该表或查询作为数据源的窗体的该属性。
下列表中包含了在 ADO Properties 集合中不存在的属性,除非使用了“格式(数据表)”工具栏来设置它们,或者使用 CreateProperty 可以在 Access 数据库中添加这些属性并将其追加到 DAO 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