|
-
August 22nd, 2001, 06:40 AM
#1
Getting Primary Keys of Access Tables with VB
Does anyone have an idee how I can get, in any way, the primary key of an table (in Microsoft Access) if you don't know the tablestructure? I'm on a project in Visual Basic where I have to get to know in one way or another what the primary key of each table is. But I have no idee if it is possible and if so, how to do it. If anyone has an idee, please let me know, it would help me a lot. Thanx
-
August 22nd, 2001, 07:19 AM
#2
Re: Getting Primary Keys of Access Tables with VB
This function get's the name of the fields in the primary key of a table, note that DB is a DAO databaseobject that points to a database.
public Function GetPK(Tablename as string)
Dim td as TableDef
Dim idx as Index
Dim fld as Field
Dim Flds as string
set td = db.TableDefs(Tablename)
for Each idx In td.Indexes
If idx.Primary then
for Each fld In idx.Fields
Flds = Flds & ":" & fld.Name
next fld
End If
next idx
GetPK = mid(Flds, 2)
End Function
Tom Cannaerts
[email protected]
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
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
|