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!

Read through the results of a query one record at a time.

Status
Not open for further replies.

strangeryet

Programmer
Jul 8, 2004
159
US
I need to pull some information from an Access table or
via a query. But I need to read one record at a time, perform some action and then read the next record.
This will continue until eof.
Does anyone have code that will do this?

Thank you

ps. This sounds like a simple procedure. Can it be done or do I need to somehow load the result of the query into an Array and then loop through the array?
Thanks
 
Do a search on RecordSet. You can use either DAO or ADO.

HTH RuralGuy (RG for short) acXP winXP Pro
Please respond to this forum so all may benefit
 
Here is some basic code to do this:
Besure to include reference for DAO

Dim strTableName As String
Dim rs As DAO.Recordset
'Load your table name
strTableName = "Table Name"
Set rs = CurrentDb.OpenRecordset(strTableName, dbOpenDynaset)
Do While Not rs.EOF
MsgBox "See Result= " & rs.Fields("FieldName1") ' from table
MsgBox "See Result= " & rs.Fields("FieldName2") ' from table
rs.MoveNext
Loop
 
databasepath = "c:\test.mdb"
sSQL = "SELECT ID, name FROM test"

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & databasepath
Set rsTest = Server.CreateObject("ADODB.Recordset")
With rsTest
'to use adLockReadOnly and adOpenForwardOnly do not forget to include adovbs.inc, otherwise use the values 1 and 0
.Open sSQL, conn, adLockReadOnly, adOpenForwardOnly
While Not .EOF
'an example how to get the data
ID = .Fields("ID")
name = .Fields("name")
'Do the things you want to do
.MoveNext
Wend
End With
Set rsTest = Nothing
conn.Close
Set conn = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top