Check to see if column exists in access table

Is there a way with vb in access to check and see if a column exists and then do something if it does?
woodan1Asked:
Who is Participating?
 
harfangConnect With a Mentor Commented:
"if a column exists" means "if a field exists" when you are referring to a table.

Try this function:

Function FieldExists(pstrTable As String, pstrField As String) As Boolean

    Dim fld As Field

On Error Resume Next

    Set fld = CurentDb.TableDefs(pstrTable).Fields(pstrField)
    If Err Then
        Err.Clear
    Else
        FieldExists = True
    End If

End Function


If you are talking about a datasheet (table or query), you could use the fields collection of that object in a similar manner.

Hope this helps
0
 
woodan1Author Commented:
Thanks harfang.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.