Dec 5, 2002 #1 rushdib Programmer Joined Jun 12, 2001 Messages 203 Location US Hi, How do I create primary keys for a table in VBA? Thanks in advance, Rushdi
Dec 5, 2002 #2 cmmrfrds Programmer Joined Feb 13, 2000 Messages 4,690 Location US 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? Upvote 0 Downvote
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?
Dec 6, 2002 Thread starter #3 rushdib Programmer Joined Jun 12, 2001 Messages 203 Location US Yes, the table already has a field. I created the table using make table query. Upvote 0 Downvote
Dec 6, 2002 #4 cmmrfrds Programmer Joined Feb 13, 2000 Messages 4,690 Location US 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. http://dbforums.com/showthread.php?threadid=499823 Upvote 0 Downvote
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. http://dbforums.com/showthread.php?threadid=499823