Results 1 to 3 of 3
  1. #1
    manics31 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Location
    Philadelphia
    Posts
    23

    Access Query to Excel question


    Good morning/Afternoon everyone,
    I have the following code to export a query to Excel and so far it exports fine, it prompts the user where to save. The issue is when the user opens the .xlsx file, excel says that the file is invalid or corrupted, here is the code, can someone tell me where I went wrong.

    Code:
    Private Sub Command22_Click()
    Dim stDocName As String
    Dim vRet, vFile
    
    stDocName = "QryPVTPreviousQuater"
    vRet = UserPickFile()
    
    
    If vRet <> "" Then
        If InStr(vRet, ".xlsx") = 0 Then vRet = vRet & ".xlsx"
        vFile = vRet
        DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, stDocName, vFile
         End If
    
    End Sub
    Thanks in advance.

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    its usu because the file type does not match the extension,
    new format xl in .xls,
    or visa versa.

    The file is just fine. Excel is confused.
    But if the data is new xl and extension .xlsx, and still gives the error....
    It may be due to Access creating it. but it still opens.

  3. #3
    manics31 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2016
    Location
    Philadelphia
    Posts
    23
    Gotcha, that makes sense.
    Thank you ranman256.

    Quote Originally Posted by ranman256 View Post
    its usu because the file type does not match the extension,
    new format xl in .xls,
    or visa versa.

    The file is just fine. Excel is confused.
    But if the data is new xl and extension .xlsx, and still gives the error....
    It may be due to Access creating it. but it still opens.

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

Similar Threads

  1. Replies: 3
    Last Post: 07-08-2015, 08:59 AM
  2. Replies: 3
    Last Post: 03-21-2014, 04:28 PM
  3. Excel to Access: Conceptual question
    By dcfrancis in forum Database Design
    Replies: 2
    Last Post: 05-04-2012, 05:25 AM
  4. ACCESS VB using Excel Dates Question
    By jscriptor09 in forum Programming
    Replies: 1
    Last Post: 10-11-2011, 07:42 PM
  5. Excel / access report question.
    By Bcitral in forum Access
    Replies: 3
    Last Post: 06-20-2011, 10:46 AM

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