PC Review


Reply
Thread Tools Rate Thread

How do I loop through table columns without using column names?

 
 
=?Utf-8?B?dG1qMDAzNDU=?=
Guest
Posts: n/a
 
      3rd Jun 2005
I have imported an Excel worksheet as an Access table. Access assigns the
column names (Field1, Field2, ...... Fieldn).

I want to read a row, loop through those columns, read the next row, etc.

So it's a "Do Until no more columns" nested inside a "Do until no more rows".

The reason I need to do this is that each day I will import a new version of
the worksheet, overwriting the table I import to. From day to day, there will
be a different number of rows (no problem there) and also a different number
of columns (aye, there's the rub!)

Any ideas how to do this?

 
Reply With Quote
 
 
 
 
Allen Browne
Guest
Posts: n/a
 
      3rd Jun 2005
Something like this:


Function ShowRecordsAndFields()
Dim rs As DAO.Recordset
Dim fld As DAO.Field

Set rs = DBEngine(0)(0).OpenRecordset("Table1")
Do While Not rs.EOF
For Each fld In rs.Fields
Debug.Print fld.Name & " = "; rs(fld.Name),
Next
Debug.Print
rs.MoveNext
Loop
rs.Close
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"tmj00345" <(E-Mail Removed)> wrote in message
news:8F72EBC7-001E-4683-9D0E-(E-Mail Removed)...
>I have imported an Excel worksheet as an Access table. Access assigns the
> column names (Field1, Field2, ...... Fieldn).
>
> I want to read a row, loop through those columns, read the next row, etc.
>
> So it's a "Do Until no more columns" nested inside a "Do until no more
> rows".
>
> The reason I need to do this is that each day I will import a new version
> of
> the worksheet, overwriting the table I import to. From day to day, there
> will
> be a different number of rows (no problem there) and also a different
> number
> of columns (aye, there's the rub!)
>
> Any ideas how to do this?
>



 
Reply With Quote
 
Rick Brandt
Guest
Posts: n/a
 
      3rd Jun 2005
tmj00345 wrote:
> I have imported an Excel worksheet as an Access table. Access assigns
> the column names (Field1, Field2, ...... Fieldn).
>
> I want to read a row, loop through those columns, read the next row,
> etc.
>
> So it's a "Do Until no more columns" nested inside a "Do until no
> more rows".
>
> The reason I need to do this is that each day I will import a new
> version of the worksheet, overwriting the table I import to. From day
> to day, there will be a different number of rows (no problem there)
> and also a different number of columns (aye, there's the rub!)
>
> Any ideas how to do this?


Your Recordset has a Fields collection so you can use...

Dim fld as Field

For Each fld in rs.Fields
'do something
Next fld



--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I separate last, first names from 1 column into 2 columns? SDoc Microsoft Excel Misc 3 26th Jun 2009 04:34 PM
Table with many Column Names - How to efficiently generate a list ofhyperlinks to each Column Header Mike C Microsoft Excel Discussion 1 29th Aug 2008 10:53 PM
Loop through table of columns and rows wfgfreedom@gmail.com Microsoft Excel Programming 9 20th Jan 2008 11:36 PM
loop through table columns =?Utf-8?B?Q0QgVG9t?= Microsoft Access Forms 4 17th Jan 2006 11:36 PM
Determine table names and column names in Access database Brian O'Haire Microsoft C# .NET 2 7th Dec 2003 01:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:39 AM.