Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract Primary Key from Access Table...? 1

Status
Not open for further replies.
Oct 13, 2004
39
US
Hi all -

I m sure this is easy I have just never done it programmatically though...

Is there a simple little VBA script that will stuff the fieldname that is the primary key of a passed in table into a variable?

Thanks in advance!!!!!!!!!
 
A starting point:
CurrentDB.TableDefs("Table1").Indexes("PrimaryKey").Fields(0).Name

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PHV

I dont understand how it works though...

That looks like you are putting the primary key value in already.

That is the bit that i dont know...I am looking to inject a function with the name of a table. The function will return the name of the primary key for that table.

You might be right with the line above but I dont understand what to do with it..

Thanks again
 
A starting point:
Public Function get1stFieldOfPK(strTable)
On Error Resume Next
get1stFieldOfPK = CurrentDb.TableDefs(strTable).Indexes("PrimaryKey").Fields(0).Name
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top