Export Access 2013 query to to excel

I would like to export an Access 2013 query to Excel with VBA and ask for file location.
skull52IT director Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
Have you tried the transferspreadsheet mmethod?

Sent from my iPhone
0
skull52IT director Author Commented:
No... will that ask where to save it?
0
Dale FyeOwner, Developing Solutions LLCCommented:
It will, or will allow to enter a default file name.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

PatHartmanCommented:
Here's a sample from one of my apps.
Me.txtPath is a text box on the form that is running the export.  the code adds the file name in the format
ClientList20150315.xls

    sFileName = Me.txtPath & "\ClientList_" & Format(Date, "yyyymmdd") & ".xls"
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "TempQD", sFileName
0
skull52IT director Author Commented:
Pat,
I like being able to add a file name and the current date to the to the output, i assume that  TempQD would be the query that would generate the output. I also assume that  sFileName  would be DIM as String
0
skull52IT director Author Commented:
also I am using excel 2010 and 2013 would the acSpreadsheetTypeExcel9 still be 9 or should it be 12 or 14
0
skull52IT director Author Commented:
OK... I am using the following code
Private Sub Command357_Click()
Dim strPath As String

 strPath = "X:\ATI\Stocking Dealer\SDP 2015\STOCKING_DEALER_" & Format(Date, "yyyymmdd") & ".xlsx"
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qryDealers", strPath
End Sub

Open in new window

to export to excel it exports fine but when trying to open it, it is giving me the following error "excel cannot open the file .xlsx because the file format or file extension is not valid"
0
PatHartmanCommented:
This is an Access gotcha!  You would think that acSpreadsheetTypeExcel12 would point to the "normal" spreadsheet format but it doesn't!!!  It points to .xlsb or maybe .xlsm. Who knows.  The option that points to the "normal" spreadsheet format (.xlsx) is the one with the "unnormal" name - acSpreadsheetTypeExcel12Xml.  Now that makes sense???
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skull52IT director Author Commented:
Oh yeah, that make perfect sense why wouldn't you think that XML would translate into xlsx :) Thanks Pat that worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.