Hey Pookaroo85,
You are on the right track. Typically, when opening a Report in this manner, the Reports RecordSource is not changed. The RecordSource is setup to return a all records then when the Report is opened with the DoCmd.OpenReport method, a WhereCondition is supplied to filter the Report down to only the Records that are desired. It's basically splitting your Query into two parts, the part that selects the fields is what the Report is saved with, while the part that selects which rows is supplied by the Form when the Report is opened.
So what you will want to do is set the RecordSource of your report to a Query that you have made that returns all records(the last bullet point from Post #1), then build up the stWhereCondition string to filter Report.
This is an Example that should be close to what you need, but you will need to tweak it:
- If Len(Nz(Me.IDH.Value, "")) > 0 Then
-
stWhereCondition = stWhereCondition & "IDH='" & Me.IDH.Value & "'"
-
End If
-
If IsDate(Me.StartDate.Value) AND IsDate(Me.EndDate.Value) THEN
-
If Len(stWhereCondition) > 0 THEN stWhereCondition = stWhereCondition & " AND "
-
stWhereCondition = stWhereCondition & "[NameOfDateField] Between #" & Me.StartDate.Value & "# AND #" & Me.EndDate.Value & "#)"
-
End If