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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding PK of given table name in Access? 1

Status
Not open for further replies.

Vachaun22

Programmer
Oct 7, 2003
171
US
I need to find the primary key field in a given table from Access just a SQL statement in order to hide that field from the form.

I'm not sure what I need to query on in order to find this. Can anyone give me some suggestions? Thanks in advance.
 
You may use this VBA function:
Code:
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 FAQ181-2886
 
I'm actually coding in VB6 using ADODB connections, so that unfortunately won't help I don't think.
 
You may play with an ADOX.Catalog object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I did find that, but that would require a bunch of code changes.

I did however find the OpenSchema functionality, which I'm going to use. It seems to work properly. Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top