How To Use ADO to Determine If a Field Is an AutoNumber Field in an Access Table (304100)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 2.6

This article was previously published under Q304100

SUMMARY

Using the Microsoft OLE DB Provider for Jet 4.0 in ADO, you can use the dynamic property ISAUTOINCREMENT to determine if a field is an AutoNumber field. This property also allows you to determine if the field is an Identity field in a Microsoft SQL Server table.

MORE INFORMATION

The following code illustrates the use of the dynamic property ISAUTOINCREMENT:
Dim cn As ADODB.Connection
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
             "Data Source=<path to mdb>;Persist Security Info=False"

Set ADOCon = New ADODB.Connection
With ADOCon
    .ConnectionString = strConnect
    .Open
End With
         
 Dim rs As ADODB.Recordset
 Set rs = New ADODB.Recordset
 rs.ActiveConnection = ADOCon
 rs.CursorLocation = adUseServer
 rs.CursorType = adOpenStatic
 rs.Open "Select * from table1"
 For x = 0 To rs.Fields.Count - 1
    If rs.Fields(x).Properties("ISAUTOINCREMENT") = True Then
        MsgBox "Field " & rs.Fields(x).Name & " is Autoincrement"
    End If
 Next x
				

Modification Type:MinorLast Reviewed:8/30/2004
Keywords:kbhowto KB304100