Sue,
Knowing a Primary Key be one or more fields, this sub will print them
to the debug window:
Sub PrintPrimaryKeys(tblName As String)
Dim fld As DAO.Field
Dim tbl As DAO.TableDef
Dim dbs As DAO.Database
Set dbs = CurrentDb
Set tbl = dbs.TableDefs(tblName)
Dim idx As DAO.Index
Set idx = tbl.Indexes("primarykey")
For Each fld In idx.Fields
Debug.Print fld.Name
Next fld
End Sub
you can call it like:
PrintPrimaryKeys "Employees"
If you know there is just one, you could:
Debug.Print
CurrentDB.TableDefs("tblBrands").Indexes("PrimaryK ey").Fields(0).Name
Chris Nebinger
SueA wrote:
Can anyone help me with the code to retrieve the name of the PrimaryKey
field of the current table?
For instance:
qryMfrsAndBrands is based on the tables: tblBrands and tblMfrs
formMfrsBrands is based on qryMfrsAndBrands
fieldBrandName is on the form and comes from tblBrands via
qryMfrsAndBrands.
I'd like to retrieve the name of the primary key field for tblBrands.
Thanks again.
I'm still very new at this - but not as new as I was yesterday!
-Sue