กระทู้เก่าบอร์ด อ.สุภาพ ไชยา
246 1
URL.หัวข้อ /
URL
Set Primarykey on imported table using VBA Code
มีคนถามคำถามนี้ไว้ที่
http://www.quicktechusa.com/msgboard/wwwboard.pl?read=17126
เขาถามไว้ดังนี้
I have an Access 2000 database that I have to import a bunch of tables into. Once in there I need to setup some primarykeys in the tables so I can use the Seek method on them. Can this be done using VBA? If so, how?????? I am pulling my hair out trying to figure it out!!!
Any help would be greatly appreciated.
Thanks,
Kevin Russell
แปลเป็นไทย
"ต้องการจะกำหนด Primary ให้ฟีลด์ในตารางด้วยโค้ด จะทำอย่างไร"
ผมได้แนะนำโค้ดไว้ดังนี้
Sub AddPrimaryX()
Dim dbs As Database
Dim tdf As TableDef
Dim idx As Index
Set dbs = CurrentDb
Set tdf = dbs.TableDefs("YourTargetTable")
With tdf
Set idx = .CreateIndex("AnyIndexNameYou'dlike")
idx.Fields.Append idx.CreateField("TheFieldNameToBeThePrimaryKey")
idx.Primary = True
.Indexes.Append idx
End With
dbs.Close
End Sub
http://www.quicktechusa.com/msgboard/wwwboard.pl?read=17126
เขาถามไว้ดังนี้
I have an Access 2000 database that I have to import a bunch of tables into. Once in there I need to setup some primarykeys in the tables so I can use the Seek method on them. Can this be done using VBA? If so, how?????? I am pulling my hair out trying to figure it out!!!
Any help would be greatly appreciated.
Thanks,
Kevin Russell
แปลเป็นไทย
"ต้องการจะกำหนด Primary ให้ฟีลด์ในตารางด้วยโค้ด จะทำอย่างไร"
ผมได้แนะนำโค้ดไว้ดังนี้
Sub AddPrimaryX()
Dim dbs As Database
Dim tdf As TableDef
Dim idx As Index
Set dbs = CurrentDb
Set tdf = dbs.TableDefs("YourTargetTable")
With tdf
Set idx = .CreateIndex("AnyIndexNameYou'dlike")
idx.Fields.Append idx.CreateField("TheFieldNameToBeThePrimaryKey")
idx.Primary = True
.Indexes.Append idx
End With
dbs.Close
End Sub
1 Reply in this Topic. Dispaly 1 pages and you are on page number 1
1 @R06514
Time: 0.1320s