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

recordset whithin loop

Status
Not open for further replies.

sf123

Programmer
Oct 9, 2002
30
US
I am trying to do a query in a loop because the variable in my query keeps changing. I do the query record the information returned fromt the recordset, increment the variable and start the loop over. For some reason when the query isn't in the loop it works fine and does the logic once but when I try to put the query in the loop I get an error. Here is my code (some words have been replaced with **** for protection):

strcon = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=*******;Password=*******;Initial Catalog=******;Data Source=*******"
con1.Open strcon

For i = 2 To 5
'This lables the columns
Sheets(2).Rows.Cells(1, i) = tempTime & " to " & tempTime + timeSegments
sqlQuery = " ********* "
rs.Open sqlQuery, con1, adOpenKeyset, adLockOptimistic, adCmdText


Do
'I tried putting in this if statement but it didn't help
'If (rs.BOF Or rs.EOF) Then
rs.MoveFirst



It gets stuck on rs.MoveFirst
I keep getting the following error:
Run-time error '3021'
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.

Any clue why?
Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top