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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating primary keys using VBA

Status
Not open for further replies.

rushdib

Programmer
Jun 12, 2001
203
US
Hi,
How do I create primary keys for a table in VBA?

Thanks in advance,

Rushdi
 
Does the table already have a field that you want to make the primary key or will you add a new field as the primary key?
 
Yes, the table already has a field. I created the table using make table query.
 
Here is example in using an ADO connection.

Function testit2()
Dim cn As New ADODB.Connection
Dim connString As String
Dim sql As String

'-- name of the column to make primary is id
sql = "ALTER TABLE Categorys " & _
"ADD constraint pk Primary Key(id); "

Set cn = CurrentProject.Connection
cn.Execute sql

End Function

See link.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top