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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing reports from forms

Status
Not open for further replies.

JPL333

Technical User
Mar 12, 2002
5
GB
i would like some help

i have a large report consisting of individual business letters, (the details for the lettes are found from a query on the main data).

i would like to be able to print a specific letter from the form.

i have got as far as a very simple macro to open the report, now i think i need some more advanced techniques to select from the report the letter that is open on the form.

(so if i click the print icon when on record 120 it only prints letter 120 not the whole lot)

This i think will be so simple once someone tells me how!!!

thanks anyway

JPL
 
Forget the macro and put some VB code in the click event of your form button. With this code you can open the report with a filter based on the form.

Dim Criteria as string

Criteria = "tablekeyfield = " & me!formkeyfield
docmd.openreport "ReportName",AcPrintPreview,,Criteria



If your primary key field is a text field then you will need to modify the the Criteria statement to include quotes around the field. For example:
Criteria = "CustomerId = '" & me!txtCustID & "'"
Maq [americanflag]
<insert witty signature here>
 
That has helped me unbelievably..

Cheers

 
This looks really helpful, but I cannot quite make this work for me. Here is the code I have (without error control):

Private Sub Print_report_Click()

Dim stDocName As String
Dim Criteria As String
stDocName = &quot;Monitor Print&quot;

Criteria = &quot;Monitor_no = &quot; & Me!Monitor_no
DoCmd.OpenReport stDocName, acNormal, , Criteria


End Sub

'Monitor no' is the field I want to match on the report and the form. It is just an autonumber field.
First it tells me that AcPrintPreview is not defined as a variable. If I change that to acNormal it tells me that it cannot access 'Monitor_no'. Does this sytax need a more complete reference? I was not sure what was actual code in the exmple and what was to be replaced with my information.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top