Link to home
Start Free TrialLog in
Avatar of rjef
rjefFlag 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
User generated image
Avatar of rjef
rjef
Flag of United States of America image

ASKER

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

ASKER

ran it in the query not the subform and it works
Avatar of rjef

ASKER

selected the query and not the subform query and it worked
Avatar of 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.
"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....
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.
ASKER CERTIFIED SOLUTION
Avatar of Mark Edwards
Mark Edwards
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial