CONTSRAINT PRIMARY KEY

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

I am working with a table that was created
programmatically. The name of the PRIMARY KEY was
automatically generated by Access. How can I find out
what the PRIMARY KEY name is?
 
Using DAO, you can determine the field(s) that makes up PrimaryKey (don't
forget that a primary key may be more than one field) using code such as:

Dim dbCurr As DAO.Database
Dim tdfCurr As DAO.TableDef
Dim idxCurr As DAO.Index
Dim fldCurr As DAO.Field
Dim strTableName As String

strTableName = "MyTable"
Set dbCurr = CurrentDb()
Set tdfCurr = dbCurr.TableDefs(strTableName)
Set idxCurr = tdfCurr.Indexes("PrimaryKey")
For Each fldCurr In idxCurr.Fields
Debug.Print fldCurr.Name
Next fldCurr
 
Back
Top