Ashk49
New Member
- Joined
- May 27, 2008
- Messages
- 31
Hi Guys,
I have a problem to create query in excel when try to get Data from SQL server.
First-I wrote a code to connect to ODBC with DSN=MS Access database.
code is here:
This code works fine ,Here is my problem:
Try to connect with this connection :
and same query ,but I can not get the data .!!!....If i delete the filtering part it will give me some data !!!!
Please help me !? How can I make it ?
Thanks & Regards
Ashkan
I have a problem to create query in excel when try to get Data from SQL server.
First-I wrote a code to connect to ODBC with DSN=MS Access database.
code is here:
Code:
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=" & fn & ";DefaultDir=;D" _
), Array("riverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;")), _
Destination:=Range("A1"))
.CommandText = Array( _
"SELECT PL.LineID, R.RunID, R.ProductID, M.MaterialName, PL.UnitsPerMin, RLDR.UnitWt_SET, LR.ActualUnits, LR.ActualWt, LR.DateOpened, LR.DateClosed," _
, _
"PL.ProductID, LDSL.DTReasonID, R.ProductID,L.LineName, LDSL.DateOpened, LDSL.DateClosed" & Chr(13) & "" & Chr(10) & "FROM LineDeviceStateLog LDSL, LineRun LR, Material M, Product P,Pr" _
, _
"oductLine PL, RunLineDeviceRecipe RLDR ,Line L ,Run R " & Chr(13) & "" & Chr(10) & "WHERE M.Material" _
, _
"ID = P.MaterialID AND PL.ProductID = R.ProductID AND RLDR.LineID = LDSL.LineID AND RLDR.RunID = R.RunID AND PL.LineID = LR.LineID AND " _
, _
"LR.LineID = L.LineID AND R.RunID = LR.RunID AND P.ProductID = R.ProductID AND RLDR.DeviceID = LDSL.DeviceID AND LR.LineID = LDSL.LineID " _
, _
"And (LDSL.DateOpened<{ts '" & End_Of_Day & "'}) And (LDSL.DateClosed>{ts '" & Begin_Of_Day & "'}) And (LR.DateClosed>LDSL.DateOpened) And " _
, _
"(LR.DateOpened<LDSL.DateClosed) And ((LR.DateOpened>={ts '" & Begin_Of_Day & "'} And LR.DateOpened<{ts '" & End_Of_Day & "'}))" & Chr(13) & "" & Chr(10) & "ORDER BY L" _
, _
".LineID, R.ProductID, R.RunID" _
)
This code works fine ,Here is my problem:
Try to connect with this connection :
Code:
With ActiveSheet.QueryTables.Add(Connection:= _
"ODBC;DRIVER=SQL Server;SERVER=ASHKAN;UID=;APP=Microsoft Office 2003;WSID=ASHKAN;DATABASE=Ogden_SQL_DB;Trusted_Connection=Yes" _
, Destination:=Range("A1"))
Please help me !? How can I make it ?
Thanks & Regards
Ashkan
Last edited: