Column name from recordset?

  • Thread starter Thread starter AJ
  • Start date Start date
A

AJ

Is there a way to get the column name in access while using vba? For example
I have a recordset that uses the valus reset1(1), etc. Can I figure out the
name of the column it selected?
 
AJ said:
Is there a way to get the column name in access while using vba? For
example
I have a recordset that uses the valus reset1(1), etc. Can I figure out
the
name of the column it selected?


So "reset1" is the name of the recordset? Each field in the recordset has a
Name property, so given the index you can extract the name:

strFieldName = reset1.Fields(1).Name

This code snippet loops through all the fields in the recordset and prints
their names:

Dim fld As DAO.Field

For Each fld In reset1.Fields
Debug.Print fld.Name
Next fld
 
Is there a way to get the column name in access while using vba? For example
I have a recordset that uses the valus reset1(1), etc. Can I figure out the
name of the column it selected?

I have no trace of an idea what you mean by "valus reset1(1)". Could you post
the code snippet involved?

To answer your question,

rs.Fields(1).Name

would display the name of the second field in the recordset (it's zero based).

John W. Vinson [MVP]
 
When I use:
strFieldName = reset1.Fields(1).Name
then
debug.print strfieldname

The reseult is "False". (Which is not the name of the column)?? Any
thoughts? Thanks.
 
AJ said:
When I use:
strFieldName = reset1.Fields(1).Name
then
debug.print strfieldname

The reseult is "False". (Which is not the name of the column)?? Any
thoughts? Thanks.


I'd need to see more of the code to know what's going wrong. You're aware
that the fields are numbered starting with 0, so that Recordset.Fields(1) is
the second field in the recordset?
 

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

Back
Top