DatasheetFontHeight 属性 (权限)Form.DatasheetFontHeight property (Access)

您可以使用 DatasheetFontHeight 属性来指定用于显示的字体磅值并打印字段名称和数据在数据表中的查看。You can use the DatasheetFontHeight property to specify the font point size used to display and print field names and data in Datasheet view. 读取/写入的 整数Read/write Integer.



expression:表示 Form 对象的变量。expression A variable that represents a Form object.


该属性只能在 Microsoft Access 数据库中使用。This property is only available within a Microsoft Access database.

对于DatasheetFontHeight属性, 指定的字体大小必须对DatasheetFontName属性指定的字体有效。For the DatasheetFontHeight property, the font size that you specify must be valid for the font specified by the DatasheetFontName property. 例如,宋体有只大小 8、 10、 12、 14、 18 和 24 点。For example, MS Sans Serif is available only in sizes 8, 10, 12, 14, 18, and 24 points.

下表包含在使用 "格式 (数据表) " 工具栏设置它们之前, DAO properties集合中不存在的属性, 也可以使用CreateProperty在 Access 数据库 (.mdb) 中添加它们。方法并将其追加到DAO Properties集合中。The following table contains the properties that don't exist in the DAO Properties collection until you set them by using the Formatting (Datasheet) toolbar, or you can add them in an Access database (.mdb) by using the CreateProperty method and append it to the DAO Properties collection.

DatasheetFontItalic *DatasheetFontItalic * DatasheetForeColor *DatasheetForeColor *
DatasheetFontHeight *DatasheetFontHeight * DatasheetBackColorDatasheetBackColor
DatasheetFontName *DatasheetFontName * DatasheetGridlinesColorDatasheetGridlinesColor
DatasheetFontUnderline *DatasheetFontUnderline * DatasheetGridlinesBehaviorDatasheetGridlinesBehavior
DatasheetFontWeight *DatasheetFontWeight * DatasheetCellsEffectDatasheetCellsEffect


[!注释] 当您添加或设置任何属性列出带有一个星号时,Microsoft Access 将自动添加带有星号的数据库 属性 集合中列出的所有属性。When you add or set any property listed with an asterisk, Microsoft Access automatically adds all the properties listed with an asterisk to the Properties collection of the database.


以下示例将 "产品" 表的 "数据表" 视图中的字体设置为 MS Serif, 字号设置为10磅, 字体粗细设置为中等 (500)。The following example sets the font to MS Serif, the font size to 10 points, and the font weight to medium (500) in Datasheet view of the Products table.

Sub SetDatasheetFont 
 Dim dbs As Object, objProducts As Object 
 Set dbs = CurrentDb 
 Const DB_Text As Long = 10 
 Const DB_Integer As Long = 3 
 Set objProducts = dbs!Products 
 SetTableProperty objProducts, "DatasheetFontName", DB_Text, "MS Serif" 
 SetTableProperty objProducts, "DatasheetFontHeight", DB_Integer, 10 
 SetTableProperty objProducts, "DatasheetFontWeight", DB_Integer, 500 
End Sub 

Sub SetTableProperty(objTableObj As Object, strPropertyName As String, _ 
 intPropertyType As Integer, varPropertyValue As Variant) 
 ' Set Microsoft Access-defined table property without causing 
 ' nonrecoverable run-time error. 
 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 
 On Error GoTo 0 
 MsgBox "Couldn't set property '" & strPropertyName _ 
 & "' on table '" & objTableObj.Name & "'", 48, "SetTableProperty" 
 On Error GoTo 0 
 Set prpProperty = objTableObj.CreateProperty(strPropertyName, _ 
 intPropertyType, varPropertyValue) 
 objTableObj.Properties.Append prpProperty 
 End If 
 End If 
End Sub

下面的示例在打开的 "产品" 窗体的 "数据表" 视图中进行与上一个示例相同的更改。The following example makes the same changes as the preceding example in Datasheet view of the open Products form.

Forms!Products.DatasheetFontName = "MS Serif" 
Forms!Products.DatasheetFontHeight = 10 
Forms!Products.DatasheetFontWeight = 500

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.