Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a primary key in new table from make-table query? 1

Status
Not open for further replies.

drazeni

Programmer
Apr 21, 2001
66
ZA
I have a make-table query where the new table requires a primary key on one of the fields.

Can I manipulate the make-table query (the SQL statement maybe) to set this or would the VBA approach work? If so, how would I do it?

I'm looking for the easiest possible solution.

Thanks.
 

Use the RunSQL method to create the Primary Key.

docmd.RunSQL("Alter table TableName Add Constraint pk_RecID Primary Key (RecID)")

You could also create a data definition query and execute that query with OpenQuery from a macro or VB. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Thanks tlbroadbent.... works like a bomb! :)

Just another thing, is there anyway I can programmatically create a join with this field and a field in another table?

Much appreciated. "All is not as it seems"
 

Do you mean that you want to create the relationship between the tables where this primary key is a foreign key on another table? I'm unclear about what you want to do. Please provide more detail.

You can join tables in a query without having relationships, foreign keys our referential integrity defined. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top