Loop thru Columns

foxhound

Board Regular
Joined
Mar 21, 2003
Messages
182
Hello, I did a search and could not find an answer to the following. Any suggestions would be greatly appreciated.

How would I write code to select the first record of column 1, loop thru the first record of each additional column in a table then go to 2nd record and loop thru the columns again? This pattern would continue until rs.EOF ---something like this…

Set rs = CurrentDb.OpenRecordset("Select * from customers”)

With rs
.MoveFirst
End With

Do Until rs.EOF

Do Until last column
Do whatever I want here with column 1, record 1
Do whatever I want here with column 2, record 1
Do whatever I want here with column 3, record 1
Loop
rs.movenext

Loop

Thanks in advance for any help :)
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi,

Here is some basic code for looping through a recordset using ADO. This code will work fine in Access 2000 onwards.

Code:
Sub LoopRecords()

    Dim adoRS As ADODB.Recordset, adoField As ADODB.Field

    Set adoRS = New ADODB.Recordset

    adoRS.Open "SELECT * FROM Customers", CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly


    While Not adoRS.EOF

        For Each adoField In adoRS.Fields

            'Do whatever with the field here e.g.
            Debug.Print adoField.Value

        Next adoField

        adoRS.MoveNext

    Wend

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,547
Messages
6,160,456
Members
451,647
Latest member
Tdeulkar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top