Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Printing an Invoice Introduction You probably know that, if you create a button on a form and call a report, when

you click the button, all records on the report would be printed. On a data entry form, you may want to print only the report related to the record you are viewing. This is equivalent to printing an invoice. lthough this involves writing code, only a very slight modification is necessary to implement this behavior. It consists of setting the criteria of the DoCmd.OpenReport method. Practical !earning" Printing an Invoice #. To follow with this e$ercise, open the %ollege Park uto &hop database '. (rom the (orms section of the )atabase window, double*click the +orkOrders form to open it ,. fter viewing it, switch it to )esign -iew .. On the Toolbo$, make sure the %ontrol button is down and click the %ommand /utton 0. On the form click in the (orm (ooter section 1. +hen the %ommand /utton +i2ard starts, in the first page, in the %ategories list, click 3eport Operations 4. In the ctions section, click Preview 3eport"

5. %lick 6e$t 7. In the list of reports, click +orkOrders and click 6e$t #8. In the third page of the wi2ard, change the content of the top te$t bo$ to Preview Invoice ##. %lick 6e$t #'. %hange the name of the button to cmdPreviewInvoice and click (inish #,. To customi2e the button you 9ust added, right*click it and click /uild :vent #.. %hange its code as follows"
Private Sub cmdPreviewInvoice_Click() On Error GoTo Err_cmdPreviewInvoice_Click

Dim stDocName

s Strin!

stDocName " #$orkOrders# DoCmd%O&en'e&ort stDocName( acPreview, , "WorkOrderID = " & WorkOrderID E)it_cmdPreviewInvoice_Click* E)it Sub Err_cmdPreviewInvoice_Click* +s!,o) Err%Descri&tion 'esume E)it_cmdPreviewInvoice_Click End Sub

#0. %lose the code window or ;icrosoft -isual /asic that was opened #1. To test the form, switch it to (orm -iew and navigate to a record other than the first. Then click the Preview Invoice button

You might also like