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

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

Posted on 2012-04-03
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
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 250 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 250 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

861 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