Sunday, January 24, 2010

Ab-normalization at Experts Exchange - part 20

Question today: Export 4 Queries to the same Worksheet

The problem:
I have code to export 4 queries to the same workbook in 4 different worksheets. I'm using the TransferSpreadsheet method. I would like to change the code to put the results of the query in the same worksheet but I don't know how. I don't know if it's possible but I also would like to put 2 blank lines between each query result. The queries are:
1. qry_RN
2. qry_RN_Casual
3. qry_PT
4. qry_PT_Casual.

The "answer" by capricorn1:
Use my 45 lines of VBA code. Very slow as it's done by recordset processing and I hope the tables aren't too big....
Again proof that some experts are as obsessed by "code solutions" as many amateurs.



A simple and fast solution would have been to create a UNION query and even two blank lines can be added with litle effort like:
select 1, * from qry_RN
UNION
select 2, * from tblTwoDummyLines
UNION
select 3, * from qry_RN_Casual
UNION
select 4, * from tblTwoDummyLines
UNION
select 5, * from qry_PT
UNION
select 6, * from tblTwoDummyLines
UNION
select 7, * from qry_PT_Casual
ORDER BY 1;

This query could be used for the DoCmd.TransferSpreadsheet and get the result at least 6 times faster.

Nic;o)

Still proud to be suspended from this "quality site" where wannabee experts rule and "quality" is just another word from the dictionary.
(The question can be found at: http://www.experts-exchange.com/Microsoft/Development/MS_Access/Access_Coding-Macros/Q_25079300.html)

No comments:

Post a Comment