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!

Please HELP. Question on looping through records from query

Status
Not open for further replies.

ChrisOjeda

Programmer
Apr 16, 2003
45
0
0
US
I am trying to write code that will run a select query. I then wish to step through the records one at a time to pull some data from them and send it to Excel. I am having issues with running the query and stepping through... Please help. Also, can someone explain the parameters for opening a recordset (I can't get explanations in the object browser)...

My situation:
Access 2000
Query in same database named C-PRIME DAILY SUMMARY
Code below...

Dim cnCurrent As ADODB.Connection
Dim rstDailyDQ As ADODB.Recordset

Set cnCurrent = CurrentProject.Connection
Set rstDailyDQ = New ADODB.Recordset
rstDailyDQ.ActiveConnection = cnCurrent
rstDailyDQ.Open ("C-PRIME DAILY SUMMARY")
With rstDailyDQ
.MoveFirst
Do Until rrstDailyDQs.EOF
MsgBox (rstDailyDQ![DAYS DQ])
.MoveNext
Loop
.Close
End With
 
do something like this

Dim rstDailyDQ As ADODB.Recordset
Set rstDailyDQ = New ADODB.Recordset

With rstDailyDQ
Set .ActiveConnection = CurrentProject.Connection
.CursorType = adOpenStatic
.Open "tbl_name", options:=adCmdTable
end with

Do Until rstDailyDQ.EOF
MsgBox "yadda yadda"
rstDailyDQ.MoveNext

loop
 
I tried that out but I got an infiniti loop? The query only brings back like 9 records but when I use that code it I just keep getting message boxes. Thanks for the try. Any other ideas?
 
Okay it does not loop continuously with a Table. But it does with a query. I am sure it has to do with the parameter "adCmdTable"...What option should I use for a query that I just want to step through each record???
 
According to this I can't use an Access query object for Recordset.Open...see below...

Use the Source property to specify a data source for a Recordset object using one of the following: a Command object variable, an SQL statement, a stored procedure, or a table name.

So then the question is how do open a Query in my DB to step throught he records???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top