Determine primary key fields in VBA

T

TC

(untested)

dim db as database, td as tabledef, inx as index, fld as field
set db = currentdb()
set td = db.tabledefs![YourTableNameHere]
for each inx in td.indexes
if inx.primary then
for each fld in inx.fields
msgbox fld.name
next
endif
next
set td = nothing
set db = nothing

HTH,
TC
 
T

Tik Sin

In a VBA application I need to know which fields of an
existing Access table are the primary key fields.
How do I do this?

thanks,
Tik Sin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top