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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB text string = Retrieved records from table within access 1

Status
Not open for further replies.

lube8

Technical User
Jan 8, 2004
11
0
0
US
What is the VB code for retrieving and looping records from an existing table. I have a table with 25 records and I have some VB code already set up to export my data to excel by a string (I have dim'd) I manually enter into my module. I would like the string to retrieve each record in an existing table and loop this procedure so I would have 25 excel files for each string/record that is in my table.

Like I said, right now, this is a manual process where I key the data of each field into my module for my string and run the procedure, but I have to do this 25 seperate times.
 
Hi lube8,

Not entirey sure I understand what you're asking, but to loop through a table in VBA you need a recordset and some basic code like this:

Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("
Code:
TableName
Code:
")
While Not rs.EOF
Code:
' Your code here
    '   Reference individual fields by name: e.g. rs!
Code:
FieldName
Code:
Code:
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
Set db = Nothing

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top