"Querytables.add" in a loop; result is insert in a new row each t

B

Ben

Hi, here is the problem I have: the macro s result is instead of inserting
the data in the cell of the next row(Range("K" & R & ""), a new column is
created each time.
Can you figured out the problem?

Do Until Cells(R, 5) = "TOTAL:"

R = 8
FrstDay = 7
LastDay = 14
Card1 = Cells(R, 4)
Sqlstring = "select sum(Temps_Arrondi) from Presence_BCV_App where
_Card= '" & Card1 & "' and ([Date] > '" & FrstDay
& "' and
_[Date] < '" & LastDay & "') "
connstring = "ODBC;DSN=DEV_DCI;UID=sa;PWD=abcde;Database=DEV_DCI"

With ActiveSheet.QueryTables.Add(Connection:=connstring,
Destination:=
_Range("K" & R),
Sql:=sqlstring)
.Refresh BackgroundQuery = False
End With

R = R + 1
Loop
 
B

Ben

It seems like when the datas is going to be inserted and the last Sql request
is not complete is the source of the problem.
In that case, what is the method/property with "querytables.add" to insert
the data no matter what else is done?
Please don't use that like the answer to the problem.
I'm only supposing at this point.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top