判断表或查询中是否存在某个字段:
Public Function FieldExists(accOctName As String, FieldName As String) As Boolean
'accOctName 表或查询名称
'FldName 字段名
'Dim accQry As AccessObject
FieldExists = False ' 默认值为不存在,除非字段存在。
Dim Fld As Dao.Field
Dim rst As Dao.Recordset
Set rst = CurrentDb.OpenRecordset(accOctName)
For Each Fld In rst.Fields
If Fld.Name = FieldName Then
FieldExists = True ' 找到这个字段
Exit For ' 跳出循环
End If
Next
rst.Close
Set rst = Nothing
Set Fld = Nothing
End Function
图 示:
参考文章:
【译文】判断数据库中是否存在某个查询—周芳