Results 1 to 2 of 2
  1. #1
    Bcanfield83 is offline Advanced Beginner
    Windows 7 32bit Access 2016
    Join Date
    May 2018
    Posts
    81

    Question Export Form's Record Source To Excel Spreadsheet

    Hi,



    I was wondering if anyone knows whether or not there's a way to code something in VBA that would export whichever query is listed in the form's record source property to Excel.
    In general, I know how to do all of that - typically I would do something along the lines of the below. For this, assume that the code is behind the "OnClick" property for a button on a form. The form is bound to "qry_MyData1" - thus if you go into the form properties, "qry_MyData1" would be listed under 'Record Source'.
    Code:
    Dim strQuery As String
    Dim strFileName As String
    
    
    strQuery = "qry_MyData1"
    strFileName = strQuery & ".xlsx"
    
    
    DoCmd.OutputTo acOutputQuery, strQuery, acFormatXLSX, strFileName, True
    So what I'm asking is whether the above could be tweaked to simply refer to the Record Source of the form, as opposed to explicitly listing out the query name (in a string variable, as I did in the above).
    Obviously it would only pertain to forms bound to a table or query in the DB, but that's essentially what I'm looking to do.

    Any help would be appreciated. Thanks!

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    If it's a form, I don't think you need to specify the recordsource - you just output the form

    DoCmd.OutputTo acOutputForm, "frmMyForm", acFormatXLSX, "MyTest.xls", True
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 03-19-2019, 08:35 AM
  2. Export Data to an Existing Excel Spreadsheet
    By wcrimi in forum Import/Export Data
    Replies: 16
    Last Post: 09-09-2018, 03:50 PM
  3. Export to spreadsheet with no Excel present
    By jabarlee in forum Import/Export Data
    Replies: 4
    Last Post: 08-14-2018, 02:37 PM
  4. Automate Export of a table to an Excel Spreadsheet
    By RayMilhon in forum Programming
    Replies: 3
    Last Post: 01-23-2018, 08:08 PM
  5. Replies: 21
    Last Post: 09-18-2015, 11:54 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums