Link to home
Start Free TrialLog in
Avatar of peterslove53
peterslove53

asked on

View a Report from filtered data of a subform

I ll like to view a report from filtered records of a subform. I used a commandbutton based on a query to filter the data and i need the report to carry all the filtered data of the form, ( filtered data, ordered by)

Private Sub CmdApplyFilter_Click()
Me![subform].form.RecordSource = "select * from Table2 where Table2.status not in ('complete','pending')"
Exit Sub
End Sub

' Previewing my filtered data

Private Sub CmdPreviewReport_Click()
Dim rpt As Access.Report
Dim stDocName As String
stDocName = "Request_Report"
DoCmd.OpenReport stDocName, acPreview, , Me.subform.form.Filter, , Me.subform.form.OrderBy
End Sub

this does not give me the filtered results i really need
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

try

DoCmd.OpenReport stDocName, acPreview, , "[status] not in ('complete','pending')"
Avatar of peterslove53
peterslove53

ASKER

i want the report to preview whatever filter the user chooses, the filter above is just an example
how are you ACTUALLY setting the filter of the subform. (don't post an example)
i create forms from a query of the main table, the subform is created from another form which is based on a query.  Usually the above syntax works for passing any filtered data of the subform to the report. But when i try to reduce the steps that a manual filtering result by using the query above, the report refuses to carry over the above filtered data. So the main question should have been how can i adjust the query so it works like it should. Manually filtering the form works and is carried over currently

(i pass the OpenArgs to the onload event of the report to make that work)
in this line
Me.subform.form.Filter

you need to replace the "subform"  with the name of the "subform control"
thats is exactly what i did, and its working except when i use a query to filter the record
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America 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
i seem to get it to work using Applyfilter;

Private Sub CmcApplyFilter_Click()
Me.subform.form.Filter = "status not in ( 'Complete','Deferred','Cancelled','Delivered')"
Me.subform.form.FilterOn = True
End Sub



But what if i want to add multiple filters?
<But what if i want to add multiple filters? >

create a sub routine to build the criteria for your filter in a string variable and use the string variable as you filter.