Print specific record in subform

falcondeer

Registered User.
Local time
Today, 05:23
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.
 
does your subform has Autonumber field on it?
that is the clue.
 
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: 336
does your report has the PR_ID on its recordsource?
filter by PR_ID not by P_ID.
 
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
 
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

Back
Top Bottom