6

Working with MS Access 2007, I have a query I'd like to run and export the results to a specific workbook in a saved Excel workbook. I have the following code written using DoCmd. First I open the query (this works) and then I try to output the results to excel.

DoCmd.OpenQuery "MyQueryName", acViewNormal, acEdit

DoCmd.OutputTo acOutputQuery, "Aging By Desk - Onboarding Team", acFormatXLS, _
    "filepath.SuperTest.xls", "SuperTest.xls", True

However, when this code is run, I get the following error message: "An Expression you entered is the wrong data type for one of the arguments". I've been playing around with each argument, but can't seem to locate the problem. Any ideas? Am I on the right path?

1
  • Hi Placet, when you get the error message and click on 'debug', which line is highlighted in yellow?
    – PowerUser
    Aug 16, 2013 at 18:45

1 Answer 1

6

You've got too many arguments. From Microsoft's website:

expression.OutputTo(ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart, TemplateFile, Encoding)

Take out one of those Excel filenames you have and it should work.

2
  • You both were correct, I had an extra argument. Now the macro is executed without an error. Even with the correct filepath (and i've double checked) "filepath.SuperTest.xls" the query information does not appear in the workbook SuperTest.xls when I open it. Any ideas? Aug 16, 2013 at 19:03
  • filepath.SuperText.xls doesn't look like any valid path I've ever seen. Are you sure you don't mean "" & filepath & "\SuperText.xls"? Aug 16, 2013 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.