Access 2002 - DoCmd.PrintOut producing #Error on page

I have an Access 2002 project in which I have a form (with a sub-form) and I am having problems with the DoCmd.PrintOut code I'm trying to execute when the user clicks a command button with a printer icon on it.  Before clicking the printer icon, they have 2 date controls which they fill in and click Apply to return data and display it in the sub-form.  That works great.  However, when they click on the printer icon which executes the following code:

    If MsgBox("Do you want to print this form?", vbYesNo + vbQuestion) = vbYes Then
        DoCmd.PrintOut acPrintAll
        On Error GoTo 0
    End If

When the report prints out - the form, text boxes and outline of the sub-form print fine.  But all of the boxes in the sub-form printout with #Name? or #Error in them.  Any ideas why or how I can get around this without creating a report object?
Who is Participating?
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.

Eric ShermanAccountant/DeveloperCommented:
Does Me.SetFocus set the focus to the Main Form or the Sub-Form???

I don't generally print forms ... A report object with a filter set to what you want shown on the form works best.


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
The Docmd.Printout was never meant to be robust printing option.  It was only meant for the most simplest of "quick and easy" form printing.

You will not get your desired results using this command.

You will want to build a report.

Scott C
Jeffrey CoachmanMIS LiasonCommented:
Like the other experts, I avoid printing forms (and forms with subforms) for this reason.

A report with subreports has two sets of events that must fire, so it is not clear how yours are set up., the subreport data may not be available to the printout command at the time the code is run.

Convert this to a Main/sub "Report" and you should be fine...
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.