How to build this??

I'm VBA beginner programmer.
I'd like to execute a query in Microsoft Access and then save the result in an excel file with a given name in a given sheet.
Is it possible How


Answer this question

How to build this??

  • nuno_donato


    Running this in Access always put records in A1 cell.

    strSQL = "SELECT * INTO [Excel 8.0;Database=C:\book1.xls].[Sheet1] FROM Employee"
    CurrentDb.Execute strSQL
    < xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
    Read records in DAO.Recordset in Excel and Range.CopyFromRecordSet can put anywhere of a worksheet.

    Export always put data in A1, Import can put data in any cell.

    Furthermore, CopyFromRecordset has this property: if the any column in DAO.RecordSet contain null value, the original value in the Excel cell will not be overwriten.  So you can merge existing data in Excel with data in Access by creating some "bypass" column in the Sql like "Null as FillerCol1".


  • dnenadd

    Hi Rossella,

    Here's some suggestions from the support engineer. I also have some sample code that he provided, but I'm unable to post the .zip file here on the forum. If you'd like me to email it to you just contact me at budsup@microsoft.com.

    Please ask our buddy refer to:< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

    How To Transfer Data from < xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />ADO Data Source to Excel with ADO

    http://support.microsoft.com/default.aspx scid=kb;en-us;295646  

    ============

    Sub ExportData()

    Dim strSQL As String

    strSQL = "SELECT * INTO [Excel 8.0;Database=C:\book1.xls].[Sheet1] FROM Employee"

    CurrentDb.Execute strSQL

    End Sub

    ============


    -brenda (ISV Buddy Team)



  • How to build this??