Creating a Primary Key

  • Thread starter Thread starter Max Palmer
  • Start date Start date
M

Max Palmer

I have a database which has an unbound table

This table is created at start of database & deleted after
exiting the database

I would like to create a primary key in code form & create
a join to a second table.

The reason for this is to create a subform from the second
table.
 
Max Palmer said:
I have a database which has an unbound table

This table is created at start of database & deleted after
exiting the database

I would like to create a primary key in code form & create
a join to a second table.

The reason for this is to create a subform from the second
table.

Note: This is untested.

ALTER TABLE MyTable
ADD CONSTRAINT pk_MyTable PRIMARY KEY (primary_key_column)

Then, in VBA, I believe it's wrappered via:

Public Sub TableAlteration()

Dim TableAlterationSQL AS String

TableAlterationSQL = "ALTER TABLE MyTable ADD CONSTRAINT pk_MyTable
PRIMARY KEY (primary_key_column)"

DoCMD.RunSQL TableAlterationSQL

End Sub
 
Back
Top