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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

append result sets from 2 different queries to excel

Status
Not open for further replies.

3pmilk

MIS
Jun 20, 2002
46
US
Hi, I have 2 queries. Each query gives me a result set.
What I need is to append the result from the 2nd query to the first one. How would I do that? The following is a sample of my code.
First, I use VBA to ouput the result from query 1 to an
excel spreadsheet, and it did work... what I want now is to append the result from the 2nd query to the same spreadsheet query 1 is in, except I want the result in the next column.

Right now, it looks like this

customername
-------------
Wendy
vivian

I Want

customername customer address
------------ -----------------
wendy 4315 107th
vivian 555 674th


Private Sub Command0_Click()

DoCmd.OutputTo acQuery, "Query1", "MicrosoftExcel(*.xls)", "C:\test.xls", True, ""
DoCmd.OpenQuery "Query2"
End Sub




Thanks,
Wendy

 
Wendy,

Access has some quick built-in functions for exporting to Excel. You've found one of these functions already.

Unfortunately, once you start to want to do something a little complicated, you won't be able to use the simple built-in function anymore, instead 'manually' gluing this together using "Automation".



I just noticed that it looks like you just need to append another field to your EXISTING query, which can then be exported to Excel at the same time. If this doesn't work, see my above notes about why there's no simple function to do exactly what you need.
 
unfortnately I can't use union because these two queries because they don't have the same number of columns or same column names. Any other idea besides manual intervention?
 
No, I don't mean union queries, I assume the "customer name" and "customer address" should be in the same table, thus you should be able to just pull them into a query together without any problems...
 
Can't you just JOIN the 2 queries ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top