Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / General 2 / January 2008

Tip: Looking for answers? Try searching our database.

Column name from recordset?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AJ - 30 Jan 2008 20:23 GMT
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?
Dirk Goldgar - 30 Jan 2008 20:33 GMT
> 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

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

AJ - 30 Jan 2008 21:25 GMT
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.

> > Is there a way to get the column name in access while using vba? For
> > example
[quoted text clipped - 15 lines]
>         Debug.Print fld.Name
>     Next fld
Dirk Goldgar - 30 Jan 2008 21:39 GMT
> When I use:
> strFieldName = reset1.Fields(1).Name
[quoted text clipped - 3 lines]
> 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?

Signature

Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

John W. Vinson - 30 Jan 2008 20:40 GMT
>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]
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.