Subreport - current year



I have a button on a form with the code below to open a report to display the
current year data. The report has a subreport in the footer section with a
summary. How can I get the subreport to also pull the current year on open.
I have a combo box where the user can select the year as well, and I'd like
the subreport to display the summary for whatever year report is selected.

Thanks in advance for your help.

Private Sub Command89_Click()
On Error GoTo Err_Command89_Click

Dim stDocName As String
Dim strWhere As String
Dim strCondition As String

stDocName = "Monthly"
strWhere = "Year(DueDate) = Year(Date())"
DoCmd.OpenReport stDocName, acPreview

Exit Sub

MsgBox "There is no data for this report"
Resume Exit_Command89_Click

End Sub

Duane Hookom

Subreports can be filtered in a number of different ways:

1) in the record source query with criteria like:
Year([Some Date]) = Forms!frmYrSelect!cboYear
2) setting the Link Master/Child properties to a common value/field
3) use code prior to the main report opening that changes the
SQL property of a saved query the subreport is based on.
In your case, you should be able to create a Year field in both record
sources and use it to link the subreport.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question