We help IT Professionals succeed at work.

DoCmd.OutPutTo now working as expected

rjef
rjef asked
on
32 Views
Last Modified: 2020-09-25
any suggestions on how to get this docmd.outputto to work without error
DoCmd.OutPutTo
Comment
Watch Question

Author

Commented:
typo has been corrected but still no go
DoCmd.OutputTo acOutputQuery, "Me.ReturnsINVQuery_subform", acFormatXLSX, strFilename, True

Author

Commented:
ran it in the query not the subform and it works

Author

Commented:
selected the query and not the subform query and it worked
Dale FyeOwner, Dev-Soln LLC
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2010

Commented:
Not sure why you would want to output as a form anyway, I've never tried it, always use either a report or a query.

You might try it with:
DoCmd.OutputTo acOutputQuery, "ReturnsINVQuery_subform", acFormatXLSX, strFilename, True 

Open in new window

But I'm guessing that the subform is linked to the main form with a master/child link and doing this would send all of the records to the output file.
Mark EdwardsChief Technology Officer
CERTIFIED EXPERT

Commented:
"acOutputQuery" tells the OutputTo() function to look for a QueryDef as the source object it is to use.
Since you are trying to use  a form "Me.ReturnsINVQuery_subform" as the source object, and you've told OutputTo to expect a querydef, and you are getting the error that Access can't find the object (querydef) "Me.ReturnsINVQuery_subform", I'll give you one quess why it's not working with the form, but works with the querydef.

Don't think too hard on this....
Mark EdwardsChief Technology Officer
CERTIFIED EXPERT

Commented:
If the querydef is the form's recordsource, use the form's recordsource as the source object.
Sounds like "ReturnsINVQuery_subform" is the subform container on the main form, so:
Me.ReturnsINVQuery_subform.form.recordsource

Open in new window

without quotes around it.
DoCmd.OutputTo acOutputQuery, Me.ReturnsINVQuery_subform.form.recordsource, acFormatXLSX, strFilename, True 

Open in new window

Be aware that any subform filters applied with the .Filter property will NOT apply to the subform's recordsource.
Also, "Me." is NOT part of the form's name, so "Me.ReturnsINVQuery_subform" (with the quotes around it) will always fail, no matter what you are trying to do.
Chief Technology Officer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.