testing ADO recordset for PrimaryKeys

J

Jeff Norville

I'm pulling a recordset of data based on a query into Excel; currently
I flip through the Field.Name and Field.Type properties to populate
the header rows with recordset names and types (enumerating the types
as adInteger, adVarWChar, adBoolean, etc).

I don't find a way to test the recordset to see if the field came from
a table's primary key... which doesn't seem too taxing.

Looks like I would need to go to ADODB.Connection.OpenSchema and test
the originating table to find its keys. Could that be right?

Feels like I am missing something obvious, but I hope you'll humor the
question anyway!

Thanks,
Jeff
 
R

Ratheesh

I'm pulling a recordset of data based on a query into Excel; currently
I flip through the Field.Name and Field.Type properties to populate
the header rows with recordset names and types (enumerating the types
as adInteger, adVarWChar, adBoolean, etc).

I don't find a way to test the recordset to see if the field came from
a table's primary key...  which doesn't seem too taxing.

Looks like I would need to go to ADODB.Connection.OpenSchema and test
the originating table to find its keys.  Could that be right?

Feels like I am missing something obvious, but I hope you'll humor the
question anyway!

Thanks,
Jeff

Hi Jeff,

I didnt get exactly what is your doubt, but incase if you are looking
for the heading
you can try this or make your question bit more clear -
Open your RecordSet and do the below loop before it pasting to your
destination
For ColH = 1 To RecordSet(Name of your Recordset).Fields.Count
Sheets("YourSheet").Cells(1, ColH) = RecSet.Fields(ColH -
1).Name
Next

Regards
Ratheesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top