|
-
Feb 22nd, 2000, 06:31 PM
#1
Thread Starter
Hyperactive Member
Hello VB users,
MS Access problem.
I am still searching to create a primary key for my field in a table.
In sql there is a possibility.
Can someone complete the next code for creating a primary key for the field "NewField"?
Set Ws = DBEngine.Workspaces(0)
Set Db = Ws.CreateDatabase("c:\q.mdb", dbLangGeneral)
Dim tdfNew As TableDef
Set tdfNew = Db.CreateTableDef("newTable")
tdfNew.Fields.Append tdfNew.CreateField("NewField", dbText)
Db.TableDefs.Append tdfNew
Db.Close
Nice regards,
michelle.
-
Feb 22nd, 2000, 07:39 PM
#2
Lively Member
Hi michelle,
Remember- a primary key is an index, not a field, so try adding these lines to your code:
'Put this with the other declarations:
Dim idx as Index
'Put this after you've appended the field:
Set idx = New Index
With idx
.Name = "NewFieldPrimary"
.Fields = "NewField"
.Primary = True
End With
tdfNew.Indexes.Append idx
That's it! Hope this works for you.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|