View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Faysal Aberkane Faysal Aberkane is offline
external usenet poster
 
Posts: 1
Default Code to get the primary key of table using ADO and VBA

Dim db As New ADODB.Connection
Dim resultsRS As New ADODB.Recordset

'open your database connection first

Function getPrimaryKeyName$(tableName$)
Set resultsRS = db.OpenSchema(adSchemaPrimaryKeys, Array(Empty,
Empty, tableName))
getPrimaryKeyName = resultsRS !COLUMN_NAME
End Function

I know that people often want to know how to do that (because I did)