Sub AppendDescriptionToField(ByVal TableName As String, ByVal FieldName As String, ByVal Description As String)
On Error GoTo ErrP
Dim TDS As TableDefs
Dim TD As TableDef
Dim F As dao.Field
Dim P As Property
Set TDS = CurrentDb.TableDefs
Set TD = TDS(TableName)
Set F = TD.Fields(FieldName)
Set P = F.CreateProperty("Description", dbText, Description)
F.Properties.Append P
ExitSub:
Set P = Nothing
Set F = Nothing
Set TD = Nothing
Set TDS = Nothing
Exit Sub
ErrP:
If Err.Number = 3367 Then
F.Properties("Description") = Description
Else
MsgBox Err.Number & " " & Err.Description
End If
GoTo ExitSub
End Sub
复制上面的代码到一个模块中,在其他在方就可以调用了
使用方法
AppendDescriptionToField "表名","字段名","该字段的说明文本"
在EXCEL中,先在每个有注释的列右边加一个空列,用来存放注释.然后增加一个宏,用来将工作表中的注释存到右边列的相同位置中.
Sub Comment()
Dim rng As Range
ActiveSheet.UsedRange.Select
For Each rng In Selection
On Error Resume Next
If Err = 0 Then Cells(rng.Row, rng.Column + 1).Value = rng.Comment.Text
Next
End Sub
然后补上注释列列标题,
最后将EXCEL表导入ACCESS,得到表,
1)access数据库SQL语言不支持“注释”,但是可以在表设计视图里的说明栏手动为每一个字段添加注释。见图
2)access数据库VBA代码 使用一个英文单引号 ' 做注释符号,如图
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)