What is the best way to export a lot of query data from access to exel

Tom Kosel 21 Reputation points
2022-04-22T19:51:13.353+00:00

I have a large access Query dataset (263,000+ records) that I want to export Excel. It seems that I can only export 62,000 records to go using : "DoCmd.OutputTo acOutputQuery, "Unfiltered Master Query", acFormatXLS".
Is there a better method? I would like the user to be prompted for a filename and location. I would also like to have it export in xlsx format.

Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
826 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ken Sheridan 2,671 Reputation points
    2022-04-23T16:22:52.78+00:00

    You'd need to build a dialogue form in which the user can browse to a folder and enter the file name. First add a little function to a standard module, e.g.

    Public Function BrowseFile() As String

    Dim strFile As String
    
    With Application.FileDialog(2)
        .Title = "Select folder and enter file name"
        .InitialFileName = "*.xlxs"
        If .Show Then
            strFile = .SelectedItems(1)
        Else
            MsgBox "No file selected", vbInformation
            Exit Function
        End If
    End With
    
    BrowseFile = strFile
        
    

    End Function

    Then with a button in the dialog form call the BrowseFile() function and build the line to call the TransferSpreadsheet method, assigning the BrowseFile function's return value to the FileName argument of the method.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Tom Kosel 21 Reputation points
    2022-04-23T15:04:49.387+00:00

    Ken,
    As usual, thanks for your helpful response. I got that to work except for one thing. I want the user to be prompted for the file location and name. According to the information in your link, Filename is optional. I used to use "DoCmd.TransferSpreadsheet aceport, acSpreadsheetTypeExcel9, ":unfiltered master Query", , -1" and it would open a browser to let me put it where I want. Now it would appear I have to specify a location and filename.

    I can do that, so it will be solved, but just wondering by they say filename is optional, but if you leave it out, it tells you the argument is required.

    0 comments No comments