Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print a report from a form?

Status
Not open for further replies.

lasmith05

IS-IT--Management
Nov 27, 2002
25
US
I have a service order form where you input service orders. I also have a report that prints out a service order invoice. Is there a way to make a button on the service order form print the service order you are looking at in the form?
 
Have the service order id on the form act as the criteria for a query.

Then base the report on the query that is created.

Finally, on the form add a button whose action is to open the report.
 
lasmith05
Have a query that checks your invoices. One of the columns will be the InvoiceNbr. In the Criteria for that column put [Forms]![frmServiceOrder]![InvoiceNbr] (of course, changing the name of the form and the name of the InvoiceNbr field to whatever your form and fields are named.

In the command button on the Service Order form, put code similar to the following, which I have copied from an Invoice form that I use. Again you will have to change the names to your own...
Private Sub cmdPreviewInvoiceFilter_Click()
On Error GoTo Err_cmdPreviewInvoiceFilter_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim stDocName As String

stDocName = "rptInvoiceFilter"
DoCmd.OpenReport stDocName, acPreview, "qryInvoiceFilter"

Exit_cmdPreviewInvoiceFilter_Click:
Exit Sub

Err_cmdPreviewInvoiceFilter_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewInvoiceFilter_Click

End Sub

As you will note, this code saves the record before printing it, and will print the Service Order you are looking at.

Tom
 
I've used the method that SteveR77 suggested and it works great, BUT! If I use a macro to open a form for adding a new record I run into a problem. Because the data in the form has not been sent to the table yet (before pushing the print report button), there is not ID for the report query to call upon.

So how do I setup a way (macro perhaps) that took the data in the form, appended it to the table, and THEN have the report print the new record data?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top