lokeshsu
Board Regular
- Joined
- Mar 11, 2010
- Messages
- 178
Hi all,
I have a query below which works in access data base but when i tried to run the same query from excel i am getting a run time error. Need help for the below query.
And below is the code which i tried in excel VBA
I have a query below which works in access data base but when i tried to run the same query from excel i am getting a run time error. Need help for the below query.
Code:
SELECT count(expr1) AS temp
FROM [SELECT DISTINCT [Union Query].SRNo_Out, Min(Inbound.ActivityCreatedDate) AS MinOfActivityCreatedDate1, Min(Outbound.ActivityCreatedDate) AS MinOfActivityCreatedDate, CalcWorkdays(MinOfActivityCreatedDate1,MinOfActivityCreatedDate) AS expr1
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)="Team") AND ((Inbound.OpenedDate) Between #7/1/2011# And #7/31/2011 23:59:59#) AND ((Outbound.OpenedDate) Between #7/1/2011# And #7/31/2011 23:59:59#) AND (([Union Query].Priority)="1-ASAP"))
GROUP BY [Union Query].SRNo_Out]. AS SQ
WHERE expr1<=1;
And below is the code which i tried in excel VBA
Code:
sql = "SELECT count(expr1) AS temp FROM [SELECT DISTINCT [Union Query].SRNo_Out, Min(Inbound.ActivityCreatedDate) " & _
"AS MinOfActivityCreatedDate1, Min(Outbound.ActivityCreatedDate) AS MinOfActivityCreatedDate, " & _
"CalcWorkdays(MinOfActivityCreatedDate1,MinOfActivityCreatedDate) AS expr1 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)=""Team"") AND ((Inbound.OpenedDate) " & _
"Between #" & Range("L1").Value & "# And #" & Range("L2").Value & "#) AND ((Outbound.OpenedDate) " & _
"Between #" & Range("L1").Value & "# And #" & Range("L2").Value & "#) AND (([Union Query].Priority)=""1-ASAP"")) " & _
"GROUP BY [Union Query].SRNo_Out]. AS SQ WHERE expr1<=1;"
MsgBox sql
rs.Open sql, con