Mark-
Try this:
Public Sub PrimKey(tblName As String)
'*******************************************
'Purpose: Programatically determine a
' table's primary key
'Coded by: raskew
'Inputs: from Northwind's debug window:
' Call PrimKey("Products")
'Output: "ProductID"
'*******************************************
Dim db As Database
Dim td As TableDef
Dim idxLoop As Index
Set db = CurrentDb
Set td = db.TableDefs(tblName)
For Each idxLoop In td.Indexes
If idxLoop.Primary = True Then
Debug.Print Mid(idxLoop.Fields, 2)
Exit For
End If
Next idxLoop
db.Close
Set db = Nothing
End Sub
HTH - Bob
mark_aok wrote:
>Hi all,
I need to determine the name of the primary key in a table, but this
must be done using VBA.
I was looking for something like,
for each field in someRecordset.fields
if field.type="primaryKey" then
do something
end if
Next
Does anyone know if a property exists for primary key??
Thanks
Mark
--
Message posted via
http://www.accessmonster.com