Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


printing a report based on information in a form that is on screen

Posted on 2012-04-03
Medium Priority
Last Modified: 2012-08-14
I have a form that i have created and at the top of the form i created a command button the user can press to print a report based on the information they have put in the form.  The field that I use as the control field is called Bill.  Once the form is filled out they press a button at the top labeled Print and they are supposed to see a print preview of a report that has the information they just typed into the form.  The form accepts all the information and the table retains all of the data but the report is blank.  Below is the code i am using for on click of the command button i created.

Private Sub Command156_Click()
On Error GoTo Err_Command156_Click
DoCmd.OpenReport "P1BOL", acViewPreview, , "[Bill]=" & Me.Bill
        Dim stDocName As String
        stDocName = "P1BOL"
        DoCmd.OpenReport stDocName, acPreview
Exit Sub

 MsgBox Err.Description
 Resume Exit_Command156_Click

End Sub
Question by:AisinAuto
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 48

Assisted Solution

by:Dale Fye
Dale Fye earned 1000 total points
ID: 37801190
You need to make sure that the current record is saved first.  Try:

Private Sub Command156_Click()

    On Error GoTo Err_Command156_Click

    me.Dirty = false
    DoCmd.OpenReport "P1BOL", acViewPreview, , "[Bill]=" & Me.Bill

    Exit Sub
 MsgBox Err.Description
End Sub
LVL 77

Accepted Solution

peter57r earned 1000 total points
ID: 37801194
You need to be sure you have saved the current record before opening your report.

Me.Dirty = False
at the start of your code.

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question