Function ExistTableField(strTableName As String, strFieldName As String) As Boolean
'=============================================================================
'用途:检测某表中是否存在某个字段
' strTableName 表示要检测的表名
' strFieldName 表示要检测的字段名
' 用法: If ExistTableField("tblFAQ", "Answer") = True Then
' MsgBox "Answer已存在tblFAQ表中"
' end if
'=============================================================================
Dim Rs As New ADODB.Recordset
Dim Conn As New ADODB.Connection
Set Conn = CurrentProject.Connection
Rs.Open "select * from " + strTableName + "", Conn, adOpenDynamic, adLockOptimistic
ExistTableField = False
For I = 0 To Rs.Fields.Count - 1
If Rs.Fields(I).Name = "" + strFieldName + "" Then
ExistTableField = True
End If
Next
Set Conn = Nothing
Set Rs = Nothing
End Function
[此贴子已经被作者于2006-7-10 12:00:41编辑过]
|