使用 Visual Basic 中的 DatasheetForeColor 屬性可以指定或確定在 Access 數(shù)據(jù)庫 (.mdb) 的“數(shù)據(jù)表”視圖中,表、查詢或窗體中的所有文字的顏色。Long 型,可讀/寫。
expression.DatasheetForeColor
expression 必需。返回“應(yīng)用于”列表中的一個對象的表達(dá)式。
以下設(shè)置信息應(yīng)用于 Microsoft Access 數(shù)據(jù)庫和 Access 項目 (.adp):
? | 可以通過在“格式(數(shù)據(jù)表)”工具欄上單擊“字體/前景色”并在調(diào)色板中單擊所需的顏色,設(shè)置該屬性。 |
? | 可以通過在“工具”菜單上單擊“選項”,使用“選項”對話框的“數(shù)據(jù)表”選項卡,設(shè)置默認(rèn)的 DatasheetForeColor 屬性。 |
設(shè)置表或查詢的 DatasheetForeColor 屬性不會影響使用該表或查詢作為數(shù)據(jù)源的窗體的該屬性。
下表包含了 DAO Properties 集合中的部分屬性,這些屬性在用戶使用“格式(數(shù)據(jù)表)”工具欄來對其進(jìn)行設(shè)置,或使用 CreateProperty 方法在 Access 數(shù)據(jù)庫中添加這些屬性并將其追加到 DAO Properties 集合中之前不存在。
DatasheetForeColor* |
|
注釋 當(dāng)添加或設(shè)置任何帶有星號的屬性時,Microsoft Access 會自動將它添加到 Properties 集合中。
以下示例使用 SetTableProperty 過程將表的字體顏色設(shè)置為深藍(lán),背景色設(shè)置為淺灰色。如果設(shè)置屬性時出現(xiàn)“找不到屬性”錯誤,可以用 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