query table macro

G

Guest

In the following, how do i change the date to read from a
cell.(uvwNFL_BatchReport.Start>={ts '2006-05-10 00:00:00'" , "})")

Any assistance will be welcome
Thanks

Full Code

With Selection.QueryTable
.Connection = _
"ODBC;DRIVER=SQL
Server;SERVER=citp2b;UID=citect;PWD=citect;APP=Microsoft Office
XP;WSID=CH-L-H8LP51S;DATABASE=NFL"
.CommandText = Array( _
"SELECT uvwNFL_BatchReport.BatchLogID,
uvwNFL_BatchReport.Pasteuriser, uvwNFL_BatchReport.Start,
uvwNFL_BatchReport.Finish, uvwNFL_BatchReport.Destination,
uvwNFL_BatchReport.TankProduct, uvwNFL_BatchR" _
, _
"eport.BatchProduct, uvwNFL_BatchReport.BatchVolumeReq,
uvwNFL_BatchReport.BatchVolumeDel" & Chr(13) & "" & Chr(10) & "FROM
NFL.dbo.uvwNFL_BatchReport uvwNFL_BatchReport" & Chr(13) & "" & Chr(10) &
"WHERE (uvwNFL_BatchReport.Start>={ts '2006-05-10 00:00:00'" _
, "})")
.Refresh BackgroundQuery:=False
End With
 
N

NickHK

Something like:
Const SINGLEQUOTE As Long=39
"WHERE (uvwNFL_BatchReport.Start>={ts " & Chr(SINGLEQUOTE) &
Range("A1").Text & Chr(SINGLEQUOTE) & "})"

Depending on the .Value/Text in the cell, you may need to use Format( ), to
get the entry in the expected format.
"WHERE (uvwNFL_BatchReport.Start>={ts " & Chr(39) & Format(Range("A1").Text,
"yyyy-mm-dd hh:mm:ss") & Chr(39) & "})"

NickHK
 

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