Solved

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

Posted on 2012-04-03
2
302 Views
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_Command156_Click:
Exit Sub

Err_Command156_Click:
 MsgBox Err.Description
 Resume Exit_Command156_Click

       
End Sub
0
Comment
Question by:AisinAuto
2 Comments
 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 250 total points
Comment Utility
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_Command156_Click:
    Exit Sub
Err_Command156_Click:
 MsgBox Err.Description
 
End Sub
0
 
LVL 77

Accepted Solution

by:
peter57r earned 250 total points
Comment Utility
You need to be sure you have saved the current record before opening your report.

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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now