lokeshsu
Board Regular
- Joined
- Mar 11, 2010
- Messages
- 178
Hi All,
I need a help in vba by executing a query by passing the parameter to the sql query which is stored in access and the parameter should be from excel. the reason why i am asking is the query is very long and i am not able to execute the query by
or do we have any other option to execute this long query in excel using vba
regards,
Lokesh
I need a help in vba by executing a query by passing the parameter to the sql query which is stored in access and the parameter should be from excel. the reason why i am asking is the query is very long and i am not able to execute the query by
Code:
sql = "select count(expr2)as expr3 from( " & _
"SELECT DISTINCT [Union Query].SRNo_Out, Min(Inbound.ActivityCreatedDate) AS MinOfActivityCreatedDate1, " & _
"Min(Outbound.ActivityCreatedDate) AS MinOfActivityCreatedDate, DateDiff(""d"",[MinOfActivityCreatedDate1]," & _
"[MinOfActivityCreatedDate])-(DateDiff(""ww"",[MinOfActivityCreatedDate1]," & _
"[MinOfActivityCreatedDate],1)+DateDiff(""ww"",[MinOfActivityCreatedDate1],[MinOfActivityCreatedDate],7)) AS Expr2 " & _
"FROM ([Union Query] INNER JOIN Inbound ON [Union Query].SRNo_Out = Inbound.SRNo_In) INNER JOIN Outbound ON " & _
"[Union Query].SRNo_Out = Outbound.SRNo_Out WHERE ((([Union Query].Segment)=""text"") AND " & _
"((Inbound.OpenedDate) Between #" & txtIRTFrom.Text & " 00:00:00" & "# And #" & txtIRTTo.Text & " 23:59:59" & "#) AND " & _
"((Outbound.OpenedDate) Between #" & txtIRTFrom.Text & " 00:00:00" & "# And #" & txtIRTTo.Text & " 23:59:59" & "#) AND " & _
"(([Union Query].Priority)='" & mProcess & "')) " & _
"GROUP BY [Union Query].SRNo_Out, DateDiff(""d"",[MinOfActivityCreatedDate1]," & _
"[MinOfActivityCreatedDate])-(DateDiff(""ww"",[MinOfActivityCreatedDate1]," & _
"[MinOfActivityCreatedDate],1)+DateDiff(""ww"",[MinOfActivityCreatedDate1],[MinOfActivityCreatedDate],7))) where expr2>1;"
or do we have any other option to execute this long query in excel using vba
regards,
Lokesh