Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to incorporate SQL in OutputToQuery

Status
Not open for further replies.

RobinHood786

Technical User
Feb 14, 2007
12
GB
Hi,

I want to reduce the number of queries I have in my database as the whole thing is looking a little bloated. (In excess of 70 queries.) Previously I’ve been using queries to as the source for exporting data to excel which works well e.g.

DoCmd.OutputTo acQuery, "Qry_CaseloadCount", "MicrosoftExcel(*.xls)", "", True

The SQL for the above example query looks like this;

SELECT Caseload.Caseworker, Count(Caseload.ProjectID) AS CountOfProjectID
FROM Caseload
GROUP BY Caseload.Caseworker;

I was wondering how to incorporate this SQL code within the OutputTo acQuery. I suspect I’ll have to do something like;

DoCmd.RunSQL "SELECT Caseload.Caseworker, Count(Caseload.ProjectID) AS CountOfProjectID " & _
"FROM Caseload " & _
"GROUP BY Caseload.Caseworker"

But I’m stuck on how to I replace the "Qry_CaseloadCount" part with this code. (If indeed that’s the way I should be approaching the issue).

All thoughts welcome.
 
Have a look at QueryDef

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the pointer PHV. Having looked through the help files and doing a ggogle search I'm still a little lost. Well quite a bit lost to be honest.

Could you possibly elaborate for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top