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 Mike Lewis 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 only one record in a report?

Status
Not open for further replies.

hshaker

Technical User
Jun 29, 2007
66
CA
Hi there,

I have created 3 reports for printing based on a multi-tabbed form. I would like to print for ie, the first report for only one record.

I have created a button that will open the first report but how do I print only the current record and not the rest.

Also, could anyone please provide me a sample code on how to print all the three reports which correspond to one form all at once. I would have to create a button that will preview all the reports but that means opening up three reports. I would like to print all the three reports for the current record all at once. But I need to have each report separate.

Thanks a lot.
 
If you used a wizard to create the button to open the report, you can modify the code to add a WHERE CONDITION to the DoCmd.OpenReport method. Assuming you have a numeric primary key, try something like:
Code:
Dim strWhere as String
strWhere = "[PrimaryKeyFieldName]=" & Me.txtPriKeyControlName
DoCmd.OpenReport stDocument, acPreview, , strWhere
If your primary key field is text
Code:
Dim strWhere as String
strWhere = "[PrimaryKeyFieldName]=""" & Me.txtPriKeyControlName & """"
DoCmd.OpenReport stDocument, acPreview, , strWhere
You can add more DoCmd.OpenReport lines to open additional reports.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Hi there,

Thank you very much for your answer. However, you fogot to answer my last question. How do you print all reports at once. I have created indiviual buttons for each report and when I click on each one. It will print the report automatically.

Thanks.
 
Apparently you didn't read my complete answer
You can add more DoCmd.OpenReport lines to open additional reports.

You could also try to combine all three reports as subreports into a single main report. This might mess up your page numbering as well as kill your page headers and footers.

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Hi there,

I don't want to open the report. I want to print it automatically. I don't want to open the report and then click on File -> Print.

I want to have the same function as the Print Report of Visual Basic. You click on the button and then it will automatically print the report without opening it.

You could please provide a sample code to print more than one report.
 
I'm not sure you understand my reply. Assuming you want to apply the same where condition to each report...

Code:
Dim strWhere as String
Dim stDocument as String
strWhere = "[PrimaryKeyFieldName]=" & Me.txtPriKeyControlName
stDocument = "rptOne"
DoCmd.OpenReport stDocument, acNormal, , strWhere
stDocument = "rptTwo"
DoCmd.OpenReport stDocument, acNormal, , strWhere
stDocument = "rptThree"
DoCmd.OpenReport stDocument, acNormal, , strWhere

Duane MS Access MVP
[green]Ask a great question, get a great answer.[/green] [red]Ask a vague question, get a vague answer.[/red]
[green]Find out how to get great answers faq219-2884.[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top