网友 静水流深(992129815) 11:01:57 问题
请问老师表设计视图中的“说明”属性,怎么用代码设置,如下图:
Accessoft--红尘如烟 11:18:54
设置某个字段“说明”属性没有现成的函数,需要用自定义函数 如下:
Function SetFieldDescription(TableName As String, _
FieldName As String, _
Description As String)
On Error GoTo ErrorHandler
Dim dbs As DAO.Database
Dim fld As DAO.Field
Const errNotFoundProperty = 3270
Set dbs = CurrentDb
Set fld = dbs.TableDefs(TableName).Fields(FieldName)
fld.Properties("Description") = Description
ExitHere:
Set dbs = Nothing
Set fld = Nothing
Set prp = Nothing
Exit Function
ErrorHandler:
If Err.Number = errNotFoundProperty Then
Set prp = fld.CreateProperty("Description", dbText, Description)
fld.Properties.Append prp
Resume
Else
MsgBox Err.Description, vbCritical, "Error"
Resume ExitHere
End If
End Function
|
把这个函数保存到模块中。
调用方法:
SetFieldDescription "表名","字段名","字段说明文字内容"
附 件:
点击下载此示例