• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 856
  • Last Modified:

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?
0
woodan1
Asked:
woodan1
1 Solution
 
harfangCommented:
"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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now