Link to home
Start Free TrialLog in
Avatar of SpaceCoastLife
SpaceCoastLife

asked on

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:

    Me.SetFocus
    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?
ASKER CERTIFIED SOLUTION
Avatar of Eric Sherman
Eric Sherman
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
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
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., ...so 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...