Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to I determine if a field (ADODB recordset) represents an autonumber? 1

Status
Not open for further replies.

FancyPrairie

Programmer
Oct 16, 2001
2,917
0
0
US
I have a SQL table that I open with ADODB. I than loop thought each of the columns of the record. Is there a property or something that tells me if a column represents an Identity Specification (i.e. autonumber)?

(NOTE: There is property entitled "IsAutoNumber". But it returns false for a field I know the Identity Specification is true and increments by 1. So that's not it. )
 
Have a look here....


Code:
Function fncFindAutonumber( _
             strTable As String, _
             Optional ByVal db As DAO.Database = Nothing) As String

    ' Return the name of the autonumber field in table <strTable>,
     ' or a zero-length string if there is none.
     
     Dim tdf As DAO.TableDef
     Dim fld As DAO.Field
     
     If db Is Nothing Then
         Set db = CurrentDb
     End If
     
     Set tdf = db.TableDefs(strTable)
     
     For Each fld In tdf.Fields
         If (fld.Attributes And dbAutoIncrField) = dbAutoIncrField Then
             fncFindAutonumber = fld.Name
             Exit For
         End If
     Next fld

    Set fld = Nothing
     Set tdf = Nothing
     Set db = Nothing

End Function



"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top