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

help to export query results into excel

Status
Not open for further replies.

upplepop

IS-IT--Management
Jun 1, 2002
173
US
I have a query that counts vital stats in a client DB and simply returns a number (i.e. one column has # of people in 93710 zip, another returns # of males, etc.) I need to export these numbers into specific cells in Excel to match the labels. How can I do this?
 
i am not sure of the sintax but you cab do it
a) create a temp table in the order of your excel spred sheet and simply unload it to a text file and import it
b) write a file to disk with a delimiter "," or "|" in the correct sequence for your spread sheet.

Hope this stimulates your thoughts
 
i am not sure of the sintax but you can do it
a) create a temp table in the order of your excel spred sheet and simply unload it to a text file and import it
b) write a file to disk with a delimiter "," or "|" in the correct sequence for your spread sheet.

Hope this stimulates your thoughts
 
I need a more user-friendly method. Anyone have more ideas?
 
Hi..

Yes you can do this in VB.

All you need is a existing Querie, and the code to export the results to Exel.

code is like this:

Private Sub Command_Click()
Dim strExcelFile As String
Dim strWorksheet As String
Dim strTable As String
Dim objDB As Database

'Change Based on your needs, or use
'as parameters to the sub
strExcelFile = "C:\MyWorkSheet.xls"
strWorksheet = "MyWorkSheet"
strDB = "C:\My.mdb"
strTable = "MyTBL Query"

Set objDB = OpenDatabase(strDB)

'If excel file already exists, you can delete it here
If Dir(strExcelFile) <> &quot;C:\MyWorkSheet.xls&quot; Then Kill strExcelFile

objDB.Execute _
&quot;SELECT * INTO [Excel 8.0;DATABASE=&quot; & strExcelFile & _
&quot;].[&quot; & strWorksheet & &quot;] FROM &quot; & &quot;[&quot; & strTable & &quot;]&quot;
objDB.Close
Set objDB = Nothing

end sub

this code works..

good luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top