Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2009
    Location
    Massachusetts
    Posts
    10

    Unanswered: Verify existence of a field in a table

    I have an application that has been distributed to several users in an organisation over time. I want to check that a certain table contains a certain field as the data tables have evolved. The aplication is in an MDE with links to data tables in an MDB. I want to make sure the user is not using an outdated data file.

    I have figured out how to verify the existence of a table, but how to do the same for a field?

    Thank you in advance,
    Pete

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Here's a solution:
    Code:
    Function FieldExists(ByVal TableName As String, ByVal FieldName As String) As Boolean
    
        Dim dbs As DAO.Database
        Dim tdf As DAO.TableDef
        Dim fld As DAO.Field
        
        Set dbs = CurrentDb
        Set tdf = dbs.TableDefs(TableName)
        For Each fld In tdf.Fields
            If fld.Name = FieldName Then
                FieldExists = True
                Exit For
            End If
        Next fld
        Set fld = Nothing
        Set tdf = Nothing
        Set dbs = Nothing
        
    End Function
    Have a nice day!

  3. #3
    Join Date
    Nov 2009
    Location
    Massachusetts
    Posts
    10

    Talking Works Great!

    Works Great! Thank you!

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •