CONTSRAINT PRIMARY KEY

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?
 
D

Douglas J. Steele

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top