PC Review


Reply
Thread Tools Rate Thread

Code to get the primary key of table using ADO and VBA

 
 
Faysal Aberkane
Guest
Posts: n/a
 
      7th Nov 2009
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set a field in a table as a Primary Key in VBA code? Rgmiket Microsoft Access VBA Modules 1 14th Mar 2008 03:18 PM
How do I enter data into one table only if a record exists in the primary table WANNABE Microsoft Access Form Coding 0 25th Jul 2006 08:20 PM
Create Table Primary Key after Make Table Query And Update Table =?Utf-8?B?Uk5VU1pAT0tEUFM=?= Microsoft Access Queries 1 3rd May 2005 08:07 PM
Cannot add primary key constraint since primary key is already set for the table Microsoft VB .NET 1 3rd Dec 2003 01:14 AM
Identifying a table's primary key fields with code Andrea Microsoft Access VBA Modules 8 4th Nov 2003 01:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:03 PM.