Print specific record in subform (1 Viewer)

falcondeer

Registered User.
Local time
Today, 13:50
Joined
May 12, 2013
Messages
101
Hi

I have the following code for the command button to print a record in the subform which lies in the main form:

Dim strReportName As String
Dim strCriteria As String
strReportName = "rptWA2"
strCriteria = "P_ID= " & Nz(Me!P_ID, 0)
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

The problem is that if I have more than one record in the subform, it will always print the first record no matter what .

Now, how could I print specific record in the subform.

Thanks.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:50
Joined
May 7, 2009
Messages
19,169
does your subform has Autonumber field on it?
that is the clue.
 

falcondeer

Registered User.
Local time
Today, 13:50
Joined
May 12, 2013
Messages
101
does your subform has Autonumber field on it?
that is the clue.
yes It has see the pic.
 

Attachments

  • PR_ID Picture.png
    PR_ID Picture.png
    10.5 KB · Views: 283

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:50
Joined
May 7, 2009
Messages
19,169
does your report has the PR_ID on its recordsource?
filter by PR_ID not by P_ID.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 16:50
Joined
May 21, 2018
Messages
8,463
Assuming your button is on the main form then
Code:
Dim strReportName As String
Dim strCriteria As String
strReportName = "rptWA2"
strCriteria = "PR_ID= " & nz(Me.SubformControlName.Form.PR_ID,0)
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
 

falcondeer

Registered User.
Local time
Today, 13:50
Joined
May 12, 2013
Messages
101
Assuming your button is on the main form then
Code:
Dim strReportName As String
Dim strCriteria As String
strReportName = "rptWA2"
strCriteria = "PR_ID= " & nz(Me.SubformControlName.Form.PR_ID,0)
DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

Thanks a lot, you made my day.
 

Users who are viewing this thread

Top Bottom