Check to see if column exists in access table

Posted on 2005-04-08
Last Modified: 2008-03-10
Is there a way with vb in access to check and see if a column exists and then do something if it does?
Question by:woodan1
    LVL 58

    Accepted Solution

    "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
            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

    Author Comment

    Thanks harfang.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In the article entitled Working with Objects – Part 1 (, you learned the basics of working with objects, properties, methods, and events. In Work…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now