[AccessD] Identifying Primary Key's

Drew Wutka DWUTKA at Marlow.com
Tue Oct 28 09:29:38 CDT 2008


Ok, well here ya go:

Function PrimaryKeys()
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
cnn.Open "C:\SomeDatabase.mdb"
Set rs = cnn.OpenSchema(adSchemaPrimaryKeys)
If rs.EOF = False Then rs.MoveFirst
Do Until rs.EOF = True
    Debug.Print rs.Fields("TABLE_NAME") & " - " & _
    rs.Fields("COLUMN_NAME") & " - " & _
    rs.Fields("PK_NAME")
    rs.MoveNext
Loop
rs.Close
Set rs = Nothing
cnn.Close
Set cnn = Nothing
End Function

Drew

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Susan Harkins
Sent: Tuesday, October 28, 2008 8:42 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Identifying Primary Key's



>
> Just curious, saw this thread and didn't say anything, because I've
been
> swamped lately, but have you looked into the Schema stuff with ADO,
it's
> pretty simple to use (just a little SQL).  I know you can use the
Schema
> to get the tables in a DB, and I was pretty sure you can get the
fields
> of a table (including most of their properties) using the Schema
stuff,
> if you haven't gotten tips on how to do that, remind me tomorrow and
> I'll whip something up for you... (had a few beers tonight, not going
to
> be checking email till tomorrow)

=====I took a look at Schema, but I don't recall what I found, or didn't

find. It might be much easier.

Susan H. 

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
The information contained in this transmission is intended only for the person or entity to which it is addressed and may contain II-VI Proprietary and/or II-VI Business Sensitive material. If you are not the intended recipient, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. You are notified that any review, retransmission, copying, disclosure, dissemination, or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited.





More information about the AccessD mailing list