Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through Records in Table

Status
Not open for further replies.

illini

Technical User
Aug 2, 2002
89
0
0
FR
Is there a simple way to loop through records in a Table?

I'm looking for something along the following:

For Each Record in Table1
x = [Company_#]

'call some other sub
Next Record

Normally, I would use DoCmd.FindRecord knowing the Company_#. In this case, I do not know all the Company_#s in Table1.

-illini
 
Hi!

Try this:

Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("YourTable", dbOpenDynaset)

If rst.EOF = True and rst.BOF = True Then
Call MsgBox("The table is empty")
Else
rst.MoveFirst
Do Until rst.EOF = True
Do your stuff here
rst.MoveNext
Loop
End If

Set rst = Nothing

Note: It could be easier and quicker to just create and run a query to update the table.

hth


Jeff Bridgham
bridgham@purdue.edu
 
Thanks, Jeff. I'll give it a try.

The purpose of this routine isn't to update, append, or delete records from the table. I simply need to pull specific pieces of data in order to print reports. Hopefully, your sample will do the trick.

Thanks.

-illini
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top