VBA query from access

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

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
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Forum statistics

Threads
1,226,729
Messages
6,192,696
Members
453,747
Latest member
tylerhyatt04

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top