Link to home
Start Free TrialLog in
Avatar of CochiseCounty
CochiseCountyFlag for United States of America

asked on

Repopulate subreport at runtime.

I have a main report with a subreport. How do I requery the query that used for the subreport everytime the main report is opened?
I have something like this, seems like it works, but the subreport picks the result from the last runtime. How do I make the subreport pick the newest result? My subreport name 'rpt_SubReport'. Thanks for help.
Dim qd As QueryDef
    Set qd = CurrentDb.QueryDefs("Q_BiweeklySupreport_Cal")
    qd.SQL = ("SELECT * FROM CalDetail WHERE ((CalDetail.ReturnDate) BETWEEN #" & dtStartDate & "# AND #" & dtEndDate & "#) ORDER BY [Type], [TagNo]")
ASKER CERTIFIED SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CochiseCounty

ASKER

The code is in the Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) in the main report. What do I do to make it not open too early? Do I need to put the code in the subreport?
Do you have the
Link Child Fields and Link Master Fields set on the Sub Report Control?

If so, you should not have to requery the sub report.

mx
OK, I made it work. I moved the code to the Report_Open, instead of Detail_Format.
Thanks for helping