Access - Macro to export query

I have created a macro to export a query into an excel file, but keep getting the error 'Could not find database'

The following are requested fields and my entries:

Transfer Type: Export
Database Type: MS Access
Database Name: City Names
Object Type: Query
Source: City Names Database
Destination: C:\Temp\Exports
Structure Only: No

The database name, Source, is 'City Names Database.' I receive an error message that this could not be found. I have tried the Source with and without the C: file path listed above.

If I leave Source blank I get the error message 'Invalid Argument.'

Your suggestions are appreciated.

Thank you.
exp vgAsked:
Who is Participating?

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

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.

Jeffrey CoachmanMIS LiasonCommented:
What is the parent command here:

Not sure what the difference between :
Database Name: City Names
Source: City Names Database

Which one is the "Database" it cannot find?
In either event, check your spelling carefully...

Not sure if the path and full name is needed:

Finally consider using code rather than macros, ...then this is easy:
DoCmd.TransferSpreadsheet acExport, , "YourQueryName", "C:\YourFoler\YourName.xls"

Open in new window

Lets see if another expert has your answer directly...
Eric ShermanAccountant/DeveloperCommented:
Which version of Access??  This worked for me ... Access 2013.


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
exp vgAuthor Commented:
Thank you everyone - my gut is telling me I am not formatting the Source name correctly.

It is Access 2013.

I did not have the db extension '.accdb' and added this - still no luck
I also tried to add [ ] around the database name 'City Names.'  So, the result is: C:\Temp\[City Names].accdb

Thank you.
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

Eric ShermanAccountant/DeveloperCommented:
Can you upload a sample db???

exp vgAuthor Commented:
Thank you everyone - I made this much harder than needed.

I was using Import/Export Data, but I needed to use Import/Export Spreadsheet

I do thank everyone fort the VBA suggestion, just not quite there yet - but headed in that direction.

Where I got caught was I thought I needed to use Import/Export Data to specify a query, but Import/Export Spreadsheet reads the queries as a table (this macro only asks for a table - so this was my area of clarification needed).

Got it to work.
exp vgAuthor Commented:
Eric ShermanAccountant/DeveloperCommented:
Glad to help and thanks for the points.

Jeffrey CoachmanMIS LiasonCommented:

that's why I asked what the Parent command was...
I was not recognizing any of those arguments...

Glad we could help
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.