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 / Queries / May 2005

Tip: Looking for answers? Try searching our database.

Use SQL to retrieve the field names in an Access table

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
quartz - 16 Oct 2004 22:05 GMT
Could someone please post back example SQL to retrieve the field names in an
Access table (i.e. not DAO and not ADO, but SQL)?

Is it possible?

Thanks in advance.
Douglas J. Steele - 16 Oct 2004 22:51 GMT
AFAIK, there's no way to retrieve the field names for an Access table using
SQL.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Could someone please post back example SQL to retrieve the field names in an
> Access table (i.e. not DAO and not ADO, but SQL)?
>
> Is it possible?
>
> Thanks in advance.
quartz - 17 Oct 2004 06:13 GMT
Thank you, Mr. Steele. What is the easiest way to accomplish this in code?
Could you please post an example? Thanks much in advance.

> AFAIK, there's no way to retrieve the field names for an Access table using
> SQL.
[quoted text clipped - 6 lines]
> >
> > Thanks in advance.
Douglas J. Steele - 17 Oct 2004 12:35 GMT
Using DAO, it would be something like the following untested aircode:

Dim dbCurr As DAO.Database
Dim tdfCurr As DAO.TableDef
Dim fldCurr As DAO.Field

  Set dbCurr = CurrentDb()
  For Each tdfCurr In dbCurr.TableDefs
     If (tdfCurr.Attributes And dbSystemObject) = 0 Then
        Debug.Print "Fields in " & tdfCurr.Name & ":"
        For Each fldCurr In tdfCurr.Fields
           Debug.Print fldCurr.Name
        Next fldCurr
        Debug.Print
     End If
  Next tdfCurr

  Set fldCurr = Nothing
  Set tdfCurr = Nothing
  Set dbCurr = Nothing

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Thank you, Mr. Steele. What is the easiest way to accomplish this in code?
> Could you please post an example? Thanks much in advance.
[quoted text clipped - 9 lines]
> > >
> > > Thanks in advance.
Altadoc - 07 Mar 2005 23:45 GMT
I have created a query which looks at a single table with some fields that
look up a person's family name by personal ID number and associates those
individuals with a file.  I want to take the name fields and concatonate them
into one for reporting; however, I get something strange even though the
concatenated field and the family name fields refer to the same relations in
the lookup table.

The query return will return 5 fields that look something like

File #   Smith   Jones   George   2, 3, 1

where the 1,2,3  are personal ID numbers autonumbered  in the personal
information file where they are looked up.  Why can't I get Smith, Jones,
George returned in the last column?

Access 2000
XP Professional
Duane Hookom - 08 Mar 2005 00:00 GMT
Consider removing all lookup fields from tables
http://www.mvps.org/access/lookupfields.htm.

If you want the "looked up" values then include the tables where the values
are actually stored.

Signature

Duane Hookom
MS Access MVP
--

>I have created a query which looks at a single table with some fields that
> look up a person's family name by personal ID number and associates those
[quoted text clipped - 15 lines]
> Access 2000
> XP Professional
John Vinson - 08 Mar 2005 01:18 GMT
>where the 1,2,3  are personal ID numbers autonumbered  in the personal
>information file where they are looked up.  Why can't I get Smith, Jones,
>George returned in the last column?

Because they do not exist in the table you're concatenating.

Lookup fields (as suggested elsethread) are often more trouble than
they're worth. They CONCEAL the actual contents of your table. What's
stored in your table *is the ID number* - that basic fact is hidden
from view, but that's what's there; so when you concatenate the
content of the table field, it's concatenating what's really there,
not what the Lookup misfeature is showing you.

To get the concatenation, create a Query joining your main table to
the lookup table (or tables); select the fields *from the table where
the value actually exists* - the lookup table - rather than the ID
field from the main table.

And... if you have split first names, middle names, and last names out
into lookup tables, I fear you're overnormalizing. Personal names are
(in most instances) valid attributes of a Person entity, and as such
should be stored as simple text fields with in the table of people. I
doubt very much that the set of all "W" middle names is a valid Entity
Class (though I know several of us who are pretty interesting people).

                 John W. Vinson[MVP]    
Skippy1313 - 01 Jun 2005 00:20 GMT
I've just come upon a godsend of an object (ResultSetMetaData) and written a
function to use it, although it's in java:

    // **************************************************************
    // Return the names of the columns of the given result set in a
    // hashtable
    // **************************************************************
    private static Hashtable GetTableColumnNames(ResultSet rs)
    {
        Hashtable ht = null;
        int intColumnIndex = 0;
        int intNumberOfColumns = 0;
        ResultSetMetaData rsmd;
        String strColumnName = null;
        String strTable = null;

        ht = new Hashtable();

        try
        {
            // Get the metadata
            rsmd = rs.getMetaData();
            intNumberOfColumns = rsmd.getColumnCount();
           
            strTable = rsmd.getTableName(2);
               
            // For each column...
            for (intColumnIndex = 1; intColumnIndex <= intNumberOfColumns;
intColumnIndex++)
            {
                // Get the column name and put it in the hashtable
                strColumnName = rsmd.getColumnName(intColumnIndex);
                ht.put("Column" + intColumnIndex, strColumnName);
            }

            // Put the number of columns in the hashtable
            ht.put("intCount", Integer.toString(intColumnIndex - 1));
        }
        catch (SQLException e)
        {
            System.out.println("GetTableColumnNames SQLException Error: " +
e.getMessage());
        }
        catch(Exception e)
        {
            System.out.println("GetTableColumnNames Exception Error: " +
e.getMessage());
        }

        return ht;

> Could someone please post back example SQL to retrieve the field names in an
> Access table (i.e. not DAO and not ADO, but SQL)?
>
> Is it possible?
>
> Thanks in advance.
 
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.