check if column exists in table

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to check and see if a column exists in a table before trying to
dynamically create a query that uses that column name.

Any suggestions?

Thank you,
Judy
 
Copy this function to a module

Function CheckIfFieldExist(TableName As String, FieldName As String) As
Boolean
' Function that check if a field exist in the table
' Return True if exist , and False if doesn't exist
On Error GoTo CheckIfFieldExist_Err
Dim I As String
CheckIfFieldExist = True
I = Application.CurrentDb.TableDefs(TableName).Fields(FieldName).Name
Exit Function
CheckIfFieldExist_Err:
If Err = 3265 Then
CheckIfFieldExist = False
Else
MsgBox Error
End If
End Function

=====================
Use this function in your code

If CheckIfFieldExist("TableName","FieldName") Then
' Exist
Else
' Doesn't Exist
End If
 
Back
Top