Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

To Specifically export a sql query to a Excel workbook

Access 2010
Excel 2010

vba routine to export chnage to specific columns on a excel workbook template.

I have a query setup to export.
Set NewQuery = CurrentDb.CreateQueryDef("Export_Temp_Subform_Query", sql)


strUserName = Environ("username")
strPath = "C:\Users\" & strUserName & "\desktop\Export_Temp_Subform_Query.xls"

    DoCmd.OutputTo acOutputQuery, "Export_Temp_Subform_Query", acFormatXLS, strPath, True


What I need:
To Specifically export to a Excel workbook.. called  "Export_InPut_Data.xlslx"

I need Field(0) in the recordset to go to ColumnA in the workbook.
I need Field(1) in the recordset to go to ColumnB  etc....

The cells on this workbook are FORMATTED  exactly as i need them.
I'm hoping when the export is completed the formatting stays in place in the EXCEL workbook ?


Thanks
Fordraiders
Avatar of Dale Fye
Dale Fye
Flag of United States of America image

instead of using transferspreadsheet, I would recommend using Excel Automation, which would allow you to use the copyFromRecordset method to push data from Access into a specific cell in range in Excel.

On my way out of the office for a meeting, but do a search on "CopyFromRecordset" here in EE and you should find some code for that.

Dale
ASKER CERTIFIED SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial