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

Print report only the last record or a specific record

Status
Not open for further replies.

Tamrak

MIS
Jan 18, 2001
213
0
0
US
Hello,

This is the information: Form name = frmBusiness; Table = tblBusiness; Report = rptBusiness

I entered the information on the form. When I save the record, I would like to print preview, based on the report (rptBusiness), for that RECORD only. If I click print report, it will print every record, which I am trying to avoid.

Is there any coding that I should use to embed with the click "Print Report" button? So that, the information for that record only will be printed? This is normally the latest or last record that we have entered.

Additionally, sometimes, the user will click the back button to a specific record. For example, we have 100 records in the table. User might click to record # 87 and want to print just that record only. Can the coding be the same based on the record pointer?

I do appreciate if someone can provide some VBA coding regarding this matter. I will put them at the "on click" command. Thank you.
 
You need to Create a Filter Query:

Create a New Query with the Table you are working from.
Add the Table to the Query. Click on the * at the top of the Table and put it in the First Field Line. In the second Field line, add your ID# from your Table. Then in the Criteria line (Under the ID#) add the following;
[Forms]![YourFormName]![ID#].
Save the Query and Name it what you want (i.e. FilterReport).
Then in Form Design, create a new Print Report command button. In the On Click Event, add;

DoCmd.RunCommand acCmdSaveRecord
On Error GoTo Err_YourReportName_Click

Dim strDocName As String

strDocName = "YourReportName"

DoCmd.OpenReport strDocName, acViewNormal, "YourQueryName"

Exit_YourReportName_Click:
Exit Sub

Err_YourReportName_Click:
' If action was cancelled by the user, don't display an error message.
Const conErrDoCmdCancelled = 2501
If (Err = conErrDoCmdCancelled) Then
Resume Exit_YourReportName_Click
Else
MsgBox Err.Description
Resume Exit_YourReportName_Click
End If


If you have any trouble, it might be easier if I emailed you a sample.

Good Luck.

Thomas Bailey
a/k/a TomCat
 
Have a look at the 4th parameter of the the DoCmd.OpenReport method.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
In relation to PHV's answer aclast

Ian Mayor (UK)
Program Error
9 times out of 10 I know what I'm talking about. This must be my tenth reply.
 
Hello PHV and ProgramError,

I still could not print the specific or the last record. Based on what I have written, here is the code.

Could you look at the 4th parameter that you mentioned whether my comma was in the right place?

Private Sub PrintPreview_Click()
On Error GoTo Err_PrintPreview_Click

Dim stDocName As String

stDocName = "rptBusiness"
DoCmd.OpenReport stDocName, acViewPreview,, acLast

Exit_PrintPreview_Click:
Exit Sub

Err_PrintPreview_Click:
MsgBox Err.Description
Resume Exit_PrintPreview_Click

End Sub

TomCat - thank you for your comments. I might try it. In the present, I would like to see whether this code will work.

Thanks again.
 
Tamrak,
Put the cursor inside the OpenReport word in your code and then press the F1 key.

ProgramError,
How is acLast relevant to my suggestion ????

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top