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

Printing a report from the form 1

Status
Not open for further replies.

wally2321

Technical User
May 30, 2001
64
US
Please help!!!
I have placed a print icon on my form. When the icon is pressed, it prints a report that I have designed. The problem is it prints all the records in the database. I would like it if the icon is clicked that only the record being displayed in the form is printed.

I am not that experienced with Access, so if possible can someone help.

Thanks,
Steve
 
Steve
Assuming that you have something that uniquely identifies each record, something such as RecordID, you can use the following in your code behind a command button...

Code:
DoCmd.OpenReport YourReportName, acPreview, "", "[RecordID]=[Forms]![YourFormName]![RecordID]"

Tom
 
Ok sorry, I went to build event (right click on the printer command icon) which brought up the following code:

Private Sub PrintForm_Click()
On Error GoTo Err_PrintForm_Click

Dim stDocName As String

stDocName = "Change Implementation Information Sheet"
DoCmd.OpenReport stDocName, acNormal

Exit_PrintForm_Click:
Exit Sub


Err_PrintForm_Click:
MsgBox Err.Description
Resume Exit_PrintForm_Click

End Sub

................
Where in the code should I put the code you suggested. Additionally, my primary key in my database is RecordID, the form name is Change Implementation Information Sheet and the report name is Change Implementation Information Sheet.

Sorry for being a little slow, but I do not mess around with this stuff that much. Can you please help me further.

Thanks,
Steve
 
Something like below

stDocName = "Change Implementation Information Sheet"
DoCmd.OpenReport stDocName, acPreview, , "[Change Implementation Information Sheet].RecordID = " & RecordID


Hope this helps
Hymn
 
Thanks so far with the help, but I am still having problems.

I tried the suggested code above and received an error, so I removed the extra comma after acPreview. I now have the following code:

Private Sub PrintForm_Click()
On Error GoTo Err_PrintForm_Click

Dim stDocName As String

stDocName = "Change Implementation Information Sheet"
DoCmd.OpenReport stDocName, acPreview, "[Change Implementation Information Sheet].RecordID = " & RecordID

Exit_PrintForm_Click:
Exit Sub

Err_PrintForm_Click:
MsgBox Err.Description
Resume Exit_PrintForm_Click

End Sub


The sheets print, but first a printer box pops up. It still tries to print all of the pages. I can limit the pages printed, but it is more of a windows print function.

I only want the sheet being displayed to be printed. Can someone please help!!

Thanks,
Steve
 
Try
DoCmd.OpenReport stDocName, acPreview, , "YourFormName.[Change Implementation Information Sheet].RecordID = " & RecordID

Hope this helps
Hymn
 
Thanks for the info... got it on your first reply, worked great for me.!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top