excel vba - How to insert into a TEMP Table in VBA -
when run following code receive error, "run-time error '1004': application-defined or object-defined error"
when select debug, following line highlighted: .refresh backgroundquery:=false
querystr = "set nocount on" & chr(13) & _ "select csd.storeno 'storeno',sum(csd.amount) totalsales " & chr(13) & _ "into #salesofthestores " & chr(13) & _ "from purchase.dbo.cashsheetdetail csd " & chr(13) & _ "inner join purchase.dbo.cashsheetheader csh on csh.transferid = csd.transferid , csh.storeno = csd.storeno " & chr(13) & _ "where csd.comments = 'total gross sales' , csh.dayenddate between '" & startdate & "' , '" & enddate & "' " & chr(13) & _ "group csd.storeno; " activesheet.querytables.add(connection:= _ "odbc;driver=sql server;server=" & div & "dbl01\sr;uid=" & user & ";app=microsoft office 2003;wsid=" & pc & ";database=purchase;trusted_connection=yes" _ , destination:=range("a1")) .refreshstyle = xloverwritecells .commandtext = querystr .refresh backgroundquery:=false
end with
your query string not return data. change sql select statement rather select (remove clause).
Comments
Post a Comment