• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 452
  • Last Modified:

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?
1 Solution
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.

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., ...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...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now