Dec 5, 2002 #1 rushdib Programmer Jun 12, 2001 203 US Hi, How do I create primary keys for a table in VBA? Thanks in advance, Rushdi
Dec 5, 2002 #2 cmmrfrds Programmer Feb 13, 2000 4,690 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 Jun 12, 2001 203 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 Feb 13, 2000 4,690 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