No Autonumber type?

sts023

Registered User.
Local time
Today, 21:07
Joined
Dec 1, 2010
Messages
40
Hi guys, it's that irritating Newbie again!

In the following code I would like to define 'pkWorks' as the Primaru Key for a newly created 'Works' Table.
There doesn't seem to be an "Autonumber" type, or a "Set as Primary Key" function.
I know I'm missing something basic and obvious - can anyone help?

(Oh, and a Merry Christmas to all!)

Code extracts follow -

.
.
.
Dim NewDB As Database
Dim NewTableDef As TableDef
Dim NewFld As Field
.
.
.
Call MakeWorksTable("Works")
.
.
.
Sub MakeWorksTable(tName As String)
'*
'** Create the Works Table.
'*
Set NewTableDef = NewDB.CreateTableDef(tName)
'*
'** Now that the database Table is created, add fields to the Table.
'*
With NewTableDef
.Fields.Append .CreateField("pkWorks", dbLong)
.Fields.Append .CreateField("MP3 Id", dbText, 12)
.Fields.Append .CreateField("AuthorSurname", dbText, 30)
.Fields.Append .CreateField("AuthorForename", dbText, 30)
.Fields.Append .CreateField("Authorfk", dbLong)
.Fields.Append .CreateField("Title", dbText, 50)
.Fields.Append .CreateField("Duration", dbInteger)
.Fields.Append .CreateField("RIPFlag", dbText, 1)
.Fields.Append .CreateField("Description", dbMemo)
End With

NewDB.TableDefs.Append NewTableDef

End Sub 'MakeWorksTable
 
Look in Access Help for info about CreateIndex method
 
Instead of table defs, use SQL to create the table and you can use the AutoIncrement and PK constraint:
Code:
Dim strSQL As String
strSQL = "CREATE TABLE mytab " & _
              "([Id] AUTOINCREMENT, " & _
              "[Desc] TEXT(50), " & _
                "CONSTRAINT [PK_MYTAB] PRIMARY KEY ([Id]));"
 
CurrentDb.Execute strSQL, dbFailOnError
 

Users who are viewing this thread

Back
Top Bottom