Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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)
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recordset with Primary Key Adax Excel Programming 2 October 6th 09 10:33 PM
Pivot Table Code - Simple Code Fix? J.W. Aldridge Excel Programming 2 April 4th 08 02:24 PM
Code for a Macro that allows a Pivot table to be repeatedly run (fora dynamic rows in a table, but static field names) Mike C[_5_] Excel Programming 1 February 11th 08 04:30 AM
Export excel table to acess table using VBA Code Jof Excel Programming 1 September 30th 05 04:46 PM
VBA Code for a pivot table to open database and to reference table current page Pete Straman Straman via OfficeKB.com Excel Programming 0 February 21st 05 03:57 AM


All times are GMT +1. The time now is 08:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"