ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   "Querytables.add" in a loop; result is insert in a new row each t (https://www.excelbanter.com/excel-programming/325420-querytables-add-loop%3B-result-insert-new-row-each-t.html)

Ben

"Querytables.add" in a loop; result is insert in a new row each t
 
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_DC I"

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

R = R + 1
Loop

Ben

"Querytables.add" in a loop; result is insert in a new row each t
 
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.


All times are GMT +1. The time now is 10:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com