Runtime error 2391 while exporting to excel RRS feed

  • Question

  • Hello everybody! I'm new at working with access, and i'm trying to export the result of a query to an already existing excel table. Following other examples I found online, I came up with this bit of code:

    DoCmd.TransferSpreadsheet acExportq, 8, "Myquery", "Destination path", True, "Range"

    I set a range in my table, and put this line of code on a button in my form. When I run the code, i get a Runtime error 2931 that informs me that field F1 does not exist in my destination table 'Myquery'.

    Is there a way to solve this error? I only found examples on importing files, but nothing on exporting.

    by the way, i'm using access and excel 2016.

    Thanks to whomever can help me!

    Wednesday, April 11, 2018 10:36 AM

All replies

  • Hi

    As I read it you spelled some of it wrong. Its not "acExportq" it is "acExport"

    Then to choose Excel version you should type "DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8"

    Below is one of mine working lines:

    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "MyQuery", PathToEXTAB, True, "OurArticles"

    Cheers // Peter Forss Stockholm

    Wednesday, April 11, 2018 11:13 AM
  • I can't see your Range value in order to determine if the syntax is correct, but have you tried changing the HasFieldNames argument to False?

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, April 11, 2018 12:57 PM
  • Hi ThatsRocketScience,

    Is your issue is solved now?

    I find that you did not done any follow up after creating this thread.

    If your issue is fixed by you then I suggest you to post your solution and mark it as an answer.

    If your issue is still exist then try to refer the suggestions given by the community members.

    If you think that the suggestions given by the community member can solve your issue then mark the helpful suggestion as an answer.

    It will help us to close this thread and it also can be helpful to other community members who will meet with same kind of issues in future.

    If you have any further questions then you can let us know about it, We will try to provide you further suggestions to solve it.

    I suggest you to update the status of this thread and take appropriate actions to close it.

    Thanks for your understanding.



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 26, 2018 9:18 AM