Open Report Based on Subform

fenhow

Registered User.
Local time
Yesterday, 18:30
Joined
Jul 21, 2004
Messages
599
Hi, I have a report that I want to run with vba. It is a receipt.

Here is the code:
DoCmd.OpenReport "rpt_Down_Payment_Receipt", acViewPreview, , "DNLID = " & DNLID

The issue is the data for the report is based on a one to many relationship.
So Main Record PK DNLID, subform PK RECID, FK DNLID

The main form is linked to the subform with DNLID

DNLID is the PK but the sub form has a unique PK for each record. So say I am on receipt #2 and want to print that. What is happening now with the above code it always opens the first ID (pk in receipts table)

Is there a way to change or add the code so the report opens with the actual receipt data I want to print?
Thanks.
Fen
 
The report is based on the same query as the subForm.
You can filter it further to the one selected record using the OpenReport FILTER parameter like you did a love.
 
Thanks, like this?
DoCmd.OpenReport "rpt_Down_Payment_Receipt", acViewPreview, , "DNLID = " & DNLID
DoCmd.OpenReport "rpt_Down_Payment_Receipt", Filter, , "CPaymentID = " & CPaymentID
 

Users who are viewing this thread

Back
Top Bottom