Primary key redifinition?

A

aligahk06

Dear All,


Could it be possible to find out primary key in a table and then redine the
primary key .

Any help?

Rgds,
Aligahk0
 
S

Stefan Hoffmann

hi,

Could it be possible to find out primary key in a table and then redine the
primary key .
Sure, open the table in design view, and locate the key symbole on the
left side of each field. Mark the new fields and press the key button.

To do it in VBA you need to inspect the Indexes collection of a TableDef
object, e.g.

Dim db As DAO.Database
Dim fd As DAO.Field
Dim ix As DAO.Index
Dim td As DAO.TableDef

Set db = CurrentDb
Set td = db.TableDefs.Item("Information")
For Each ix In td.Indexes
Debug.Print ix.Name;
If ix.Primary Then
Debug.Print ":";
For Each fd In ix.Fields
Debug.Print " "; fd.Name;
Next fd
End If
Debug.Print
Next ix
Set td = Nothing
Set db = Nothing

To redefine the primary key you need to remove this index from the
Indexes collection and add an new index with Primary = True.


mfG
--> stefan <--
 

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