[AccessD] Identifying Primary Key's

Heenan, Lambert Lambert.Heenan at AIG.com
Wed Oct 22 16:11:08 CDT 2008


Here's a little snippet of code that you should be able to figure it out
from 

            For cntFlds = 0 To curTbl.Fields.count - 1
                'If Left(curFld.Name, 4) = "bCur" Then Stop
                Set curFld = curTbl.Fields(cntFlds)
                '** Loop though all the indexes in the current table
                For cntKey = 0 To curTbl.Indexes.count - 1
                    Set curIdx = curTbl.Indexes(cntKey)
                    '** Loop though all the fields in the current index
                    For cntIdx = 0 To curIdx.Fields.count - 1
                        Set curIdxFld = curIdx.Fields(cntIdx)
                        '* is the current field part of the primary key?
			'#######################################
                        If (curFld.Name = curIdxFld.Name) And
(curIdx.Primary = True) Then
                            rstTblDetail("PrimaryKey") = True
                        End If
			'#######################################
                    Next cntIdx ' move to next field in the current index
                Next cntKey ' move to next index in current table
		Next cntFlds

By definition a primary key has an associated index, and this code says if
the name of an index on a table is the same as the name of the field, then
check the index property 'Primary'. 

Now compound primary keys are another kettle of fish.

Lambert

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Susan Harkins
Sent: Wednesday, October 22, 2008 3:10 PM
To: AccessD at databaseadvisors.com
Subject: [AccessD] Identifying Primary Key's

Is there anything in one of the system tables that identifies a table's
primary key column(s)?

Susan H. 

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list