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

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,224,590
Messages
6,179,756
Members
452,940
Latest member
rootytrip

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