A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Column name from recordset?



 
 
Thread Tools Display Modes
  #1  
Old January 30th, 2008, 08:23 PM posted to microsoft.public.access
aj
external usenet poster
 
Posts: 333
Default Column name from recordset?

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?
  #2  
Old January 30th, 2008, 08:33 PM posted to microsoft.public.access
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default Column name from recordset?

"AJ" wrote in message
...
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


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

  #3  
Old January 30th, 2008, 08:40 PM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Column name from recordset?

On Wed, 30 Jan 2008 12:23:01 -0800, AJ wrote:

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]
  #4  
Old January 30th, 2008, 09:25 PM posted to microsoft.public.access
aj
external usenet poster
 
Posts: 333
Default Column name from recordset?

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.


"Dirk Goldgar" wrote:

"AJ" wrote in message
...
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


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

  #5  
Old January 30th, 2008, 09:39 PM posted to microsoft.public.access
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default Column name from recordset?

"AJ" wrote in message
...
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?

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

 




Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:55 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.