可以在 Visual Basic 中使用 DatasheetBackColor 屬性,指定或確定在Microsoft Access 數(shù)據(jù)庫 (.mdb) 的“數(shù)據(jù)表”視圖中的整個表、查詢或窗體的背景色。Long 型,可讀/寫。
expression.DatasheetBackColor
expression 必需。返回“應(yīng)用于”列表中的一個對象的表達(dá)式。
DatasheetBackColor 屬性是代表數(shù)據(jù)表的背景色和前景色設(shè)置的 Long Integer 值。
以下設(shè)置信息應(yīng)用于 Microsoft Access 數(shù)據(jù)庫和 Access 項目 (.adp):
? | 也可以通過單擊“格式”(數(shù)據(jù)表)工具欄上的“填充/背景色”并單擊調(diào)色板上的相應(yīng)顏色來設(shè)置該屬性。 |
? | 也可以通過使用“選項”對話框的“數(shù)據(jù)表”選項卡設(shè)置 DatasheetBackColor 屬性,方法是單擊“工具”菜單上的“選項”。 |
設(shè)置表或查詢的 DatasheetBackColor 屬性不會影響使用該表或查詢作為數(shù)據(jù)源的窗體的這一屬性。
下表包含了 DAO Properties 集合中的部分屬性,這些屬性在用戶使用“格式(數(shù)據(jù)表)”工具欄對其進(jìn)行設(shè)置,或使用 CreateProperty 方法在 Access 數(shù)據(jù)庫中添加這些屬性并將其追加到 DAO Properties 集合中之前不存在。
DatasheetBackColor |
|
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