microsoft access help database programing developer
Back to Access Experts About Access Experts Access Experts Websites Access Experts Team Access Experts Services Access Experts Case Studies Access Expert Tips Contact Access Experts OUR BLOG
 
 
Access 2007 no longer exports reports to Excel
by Juan Soto
01/06/2008

Use another method to export your data
What were they thinking?
Microsoft has dropped the Export function from Access 2007, but you would never know it from your legacy code since the program will not error!  I understand the feature had it's issues, but the developer community learned how to deal with them, instead consider using the method suggested below.

Use a Temporary Table to Export Data
The following code will create a temporary table in your current Access database and then export that table to Excel. In our Access report generator we use a table, Reports, to store information used in the program. Replace the strTable and strSQL with your own versions in order to make the code work for you.

Private Sub OutputToExcel(strSpreadsheetName As String, strWhere As String)
    'Created by Juan Soto for AccessExperts.net
    'Code can be used anywhere as long as you keep above comment and this one intact
    Dim strSQL As String     'Used to create temporary table in local database
    Dim strTable As String   'Used to store temporary table name
   
    On Error GoTo ErrorHandler
   
    'Delete temporary table
    DoCmd.RunSQL "Drop Table tblTemp"

    strTable = DLookup("TableSource", "Reports", "[ReportID] = '" & Me.lstReports & "'")
    strSQL = "Select " & strTable & ".* into tblTemp from " & strTable & " Where " & strWhere
    CurrentDb.Execute strSQL, dbSeeChanges
   
    DoCmd.OutputTo acOutputTable, "tblTemp", acFormatXLS, strSpreadsheetName, True
   
    Exit Sub
   
ErrorHandler:
    If Err.Number = 3376 Then 'Table does not exist, ok to proceed
        Resume Next
    End If
End Sub

Conclusion
You may consider using a temporary Access database to store the data if your concerned with file bloating.

If you like this tip you will be delighted with our service! Call or write us today for a free quote regarding your computer needs.

Publish this article in your own corporate newsletter or publication! Contact us to obtain a free license.


Home | About Us Why PCExperts | Team | Services | Newsletter | Contact Us
Copyright © 2004