Office中国论坛/Access中国论坛

标题: 判断表中是否存在某个字段的函数 [打印本页]

作者: 竹笛    时间: 2012-12-17 14:12
标题: 判断表中是否存在某个字段的函数
'=========================================================================================
'函数名称: IsExistField
'功能描述: 检测表中是否存在某个字段
'输入参数: sTableName 必需的,表名称。
'                 sFieldName  必需的,检测的字段名称
'返 回  值: true或者false
'使用示例: IsExistField("订单表","订单日期")
'作      者: 金宇
'创建日期: 2012-12-16
'=========================================================================================
Public Function IsExistField(ByVal sTableName As String, ByVal sFieldName As String) As Boolean
    On Error GoTo ErrorHandler
    Dim fld As Field
    Dim rs As DAO.Recordset
    IsExistField = False
    Set rs = CurrentDb.OpenRecordset(sTableName)
    For Each fld In rs.Fields
        If fld.Name = sFieldName Then
            IsExistField = True
            Exit For
        End If
    Next
    rs.Close
    Set rs = Nothing
    Set fld = Nothing
ExitHere:
    Set rs = Nothing
    Set fld = Nothing
    Exit Function
ErrorHandler:
    MsgBox Err.Description, vbInformation, "提示"
    Resume ExitHere
End Function

[attach]50954[/attach]

作者: todaynew    时间: 2012-12-17 19:27
本帖最后由 todaynew 于 2012-12-17 19:29 编辑

{:soso_e120:}





欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3