Advanced Export to Excel

chrisguk

Registered User.
Local time
Today, 05:59
Joined
Mar 9, 2011
Messages
148
I have the following code running from a simple click event:

Code:
Private Sub btnWeeklyReport_Click()
On Error GoTo Do_Nothing
    
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "WeeklyReport", txtExportFile
    
    
    MsgBox "The tables have been successfully exported to " & txtExportFile & "."
Exit Sub
Do_Nothing:
    MsgBox "Export has failed.  An error occurred or the user terminated the operation."
    
End Sub

I am aware of the output to option but this one works as the user can manually adjust the filename and destination in and unbound field on the form.

My question is I dont want it to pick up a table but a Query instead and maybe with some simple formatting too.

How can this be achieved?
 
I am aware of the output to option but this one works as the user can manually adjust the filename and destination in and unbound field on the form.
The OutputTo command also has a destination part. If you leave this argument blank you will get a prompt to enter a file name and destination. A much better way of doing it. What is wrong with this method?

My question is I dont want it to pick up a table but a Query instead and maybe with some simple formatting too.
You can use a query in that method too.
 
bob larson has some great tools on his site. Check that out.
 
I have the following code running from a simple click event:

Code:
Private Sub btnWeeklyReport_Click()
On Error GoTo Do_Nothing
 
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel7, "WeeklyReport", txtExportFile
 
 
    MsgBox "The tables have been successfully exported to " & txtExportFile & "."
Exit Sub
Do_Nothing:
    MsgBox "Export has failed.  An error occurred or the user terminated the operation."
 
End Sub

I am aware of the output to option but this one works as the user can manually adjust the filename and destination in and unbound field on the form.

My question is I dont want it to pick up a table but a Query instead and maybe with some simple formatting too.

How can this be achieved?

If you want the formatting to be done then you have to control the workbook so you would need to add code to the above to open the workbook and add your formatting as well.

What formatting do you need? Have you recorded a macro in Excel to format a sample workbook and then look at the code and it will help you then apply that within your routine to export to Excel.

As you have been given some ideas about the exportin the query I will skip that part of your question.
 
I believe bob larsons code can handle some formatting.
 
Or he could have referred to Aphrodite, which I am posting in the sample db forum now. That answers your last question to my too, btw.
 

Users who are viewing this thread

Back
Top Bottom