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!
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!