首页 > 数据库 > Access > 正文

如何判断一个字段是否在表中

2024-09-07 19:04:02
字体:
来源:转载
供稿:网友

'判断一个字段是否在表中
Function BlnField(sTblName As String, sFldName As String) As Boolean

'sTblName 源表名
'要查找的字段名

Dim fld As Field
Dim rs As DAO.Recordset

BlnField = False
Set rs = CurrentDb.OpenRecordset(sTblName)
rs.Fields.Refresh
For Each fld In rs.Fields
If fld.Name = sFldName Then
BlnField = True
Exit For
End If
Next
rs.Close
Set rs = Nothing
Set fld = Nothing
End Function

Private Sub 命令0_Click()
'返回True则有此字段,False则无
MsgBox BlnField("tbl1", "ID")
End Sub
 

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表