+ Reply to Thread
Results 1 to 2 of 2

Thread: Exporting data from Access To Excel (6 Months + Only)

  1. #1
    Forum Contributor
    Join Date
    03-31-2009
    Location
    Dartford
    MS-Off Ver
    Excel 2007
    Posts
    162

    Exporting data from Access To Excel (6 Months + Only)

    Hi Guys,

    I have a database with nearly 50,000 records in including sub forms that are connected to the main form, what I want to be able to do is, have a button on my switchboard that when clicked with export any records over 6 months into an Excel Spread Sheet. Is this possible at all and if so, How do I do it.

    I only have basic knowlege of access so simple explanation is needed, sorry xx

    I found this code, can anyone tell me if it is the correct one to use, I also need to know how to create the query for the button, I can do basic queries but I need the button to on export anything that is 6 months +.

    Public Sub ModifyExportedExcelFileFormats(sFile As String)
    On Error GoTo Err_ModifyExportedExcelFileFormats
    Call ModifyExportedExcelFileFormats("X:\file.xls")
    
    Application.SetOption "Show Status Bar", True
    
    vStatusBar = SysCmd(acSysCmdSetStatus, "Formatting exported files... please wait.")
    
    Dim xlApp As Object
    Dim xlSheet As Object
    
    Set xlApp = CreateObject("Excel.Application")
    Set xlSheet = xlApp.Workbooks.Open(sFile).Sheets(1)
    
    With xlApp
    .Application.Sheets("DTDs Export data Archive").Select
    .Application.Cells.Select
    .Application.Selection.ClearFormats
    .Application.Rows("1:1").Select
    .Application.Selection.Font.Bold = True
    .Application.Cells.Select
    .Application.Selection.RowHeight = 12.75
    .Application.Selection.Columns.AutoFit
    .Application.Range("A2").Select
    .Application.ActiveWindow.FreezePanes = True
    .Application.Range("A1").Select
    .Application.Selection.AutoFilter
    End If
    .Application.ActiveWorkbook.Save
    .Application.ActiveWorkbook.Close
    .Quit
    End With
    
    Set xlApp = Nothing
    Set xlSheet = Nothing
    
    vStatusBar = SysCmd(acSysCmdClearStatus)
    
    Exit_ModifyExportedExcelFileFormats:
    Exit Sub
    
    Err_ModifyExportedExcelFileFormats:
    vStatusBar = SysCmd(acSysCmdClearStatus)
    MsgBox Err.Number & " - " & Err.Description
    Resume Exit_ModifyExportedExcelFileFormats
    End Sub
    I would appricate someones help, you may need to be patient with me lol

    Shaxx
    xx

  2. #2
    Valued Forum Contributor alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Lake County, Illinois
    MS-Off Ver
    MS Office 2010, 2007 and 2002
    Posts
    1,161

    Re: Exporting data from Access To Excel (6 Months + Only)

    I would use the following procedure.

    Create your query using the following format. Substitute your field names and table names accordingly.
    Select * from YourTableName
    WHERE YourDateField < Dateadd("m",-6,date())
    Then in the on click event for your command button use the following code
    
    Dim reportName As String
    Dim theFilePath As String
    
    
    
    reportName = "Your Query Name"
       
           
    theFilePath = "c:\Set your Path to you desktop here"
    theFilePath = theFilePath & reportName & "_" & Format(Date, "yyyy-mm-dd") & ".xlsx"
          
    DoCmd.TransferSpreadsheet acExport, 10, reportName, theFilePath, True
    
    MsgBox "Look on your desktop for the report."
    This will export your query to your local desktop as an excel spreadsheet in 2007 format

    Alan
    Last edited by alansidman; 01-30-2012 at 07:55 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0