Changing query criteria through VBA

J

Jake F

I have a query that I need to send to excel, but it needs to be grouped by
two things, region and day/night. It would take ten different queries to get
the differnent sheets that I'd need, is there a way to use one main query and
then change the criteria for those two columns to get the 10 excel workbook
sheets? Thanks.
 
A

Allen Browne

Assign the SQL property of the QueryDef.

This kind of thing:

Dim strWhere As String
Dim strSql As string

strWhere = "(SomeField = " & SomeNumber & ")"
strSql = "SELECT Table1.* FROM Table1 WHERE " & strWhere & " ORDER BY
MyField;"
CurrentDb.QueryDefs("MyQuery4Export").SQL = strSql
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top