Find out whether a column is identity

  • Hi,

    I have a SQL Server table that is a linked table within Access 2003. How can I find out in vba whether the table containes a identity column?

    The Field.Attribute flag dbAutoIncrField unfortunately only works for local Access tables...

    Regards

    Alexander

  • The same logic should work for either one:

    Function find_identity_or_autonumber(my_table As String) As String

    Dim db As DAO.Database, tdf As DAO.TableDef, fld As DAO.Field

    Set db = CurrentDb

    Set tdf = db.TableDefs(my_table)

    For Each fld In tdf.Fields

    If (fld.Properties("Attributes") And dbAutoIncrField) = dbAutoIncrField Then

    find_identity_or_autonumber = fld.Name

    Exit For

    End If

    Next fld

    Set tdf = Nothing

    Set db = Nothing

    End Function

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply