Minimize number of queries by Macro/VBA (1 Viewer)

accessfever

Registered User.
Local time
Today, 05:01
Joined
Feb 7, 2010
Messages
101
Hi, I have a 500K+ Access table which has detail information of 4 product type, tons of product names and 10 manufacturing locations. Currently, I have 40 queries to download the table by product type by locations in Excel and run a macro to execute the file downloading. I wonder if there is a way to minimize the 40 queries into just 4 queries (one query one product type) then use a macro or VBA code to breakout further by locations. I'm asking this since it is time consuming to update those 10 to 40 queries (one product type = 10 download files) when there is a request to change the download files' layout.
 

boblarson

Smeghead
Local time
Today, 05:01
Joined
Jan 12, 2001
Messages
32,059
My question is how different are your queries? Are they different just in criteria? Or at least are several like that? You don't need to build queries for each criteria. You don't even need to have a query for each product type really (unless you have a non-normalized structure where there are specific fields for specific products).

So, the question is what exactly do your queries look like?
 

accessfever

Registered User.
Local time
Today, 05:01
Joined
Feb 7, 2010
Messages
101
The query A and query B are in same layout in Excel except product type is different. The query C and query D are in same layout in Excel but different from quary A and B.
 

accessfever

Registered User.
Local time
Today, 05:01
Joined
Feb 7, 2010
Messages
101
The SQL code for each query is quite long since it tries to call out about 20 fields from the original table. I just came up with an idea if it is working or not:
A) Create just a function named "GETFIELDS" to select fields except the critera for locations and product types.
B) Then use a Click event to include the function "GETFIELDS" then add additional critera (IF ) for one location and one product type. Then export the output to an Excel file.
C) Repeat the criteria (ELSE) to download all outputs to Excel files.

Would it be working?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 13:01
Joined
Sep 12, 2006
Messages
15,690
however many queries you have shouldn't matter, surely.

can you not code them all onto a single button event?
 

Users who are viewing this thread

Top Bottom