Avatar of rjef
Flag for United States of America asked on

DoCmd.OutPutTo now working as expected

any suggestions on how to get this docmd.outputto to work without error
Microsoft AccessVBA

Avatar of undefined
Last Comment
Mark Edwards

8/22/2022 - Mon

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

ran it in the query not the subform and it works

selected the query and not the subform query and it worked
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Dale Fye

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 Edwards

"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 Edwards

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:

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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Mark Edwards

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question