Solved Ability to Create/Print Report from User Filtered Sub-form

Tamille2020

New member
Local time
Yesterday, 19:03
Joined
Feb 22, 2022
Messages
4
My end user is using a filter on a sub-form (SearchQSubform) then pressing the "PrintPDF" button that is located on the form (SearchForms). However, all the searched data in the sub-form is printing. I only wish to print the user's filtered data. I tried putting the following code in the "On Click" event procedure for the "PrintPDF" button:

Private Sub PrintPDF_Click()

DoCmd.OpenReport ReportName:="Report", View:=acViewReport, WhereCondition:="SearchQSubform.Filter"


Here are the details of the database:

Main Form Name: "SearchForms:
Sub-form Name: "SearchQSubform"
The Query the sub-form is based on: "SearchQ"
Name of the report to be viewed/printed: "Report"

What am I doing wrong? Please help.
 
Maybe try something like:

WhereCondition:=Me.SearchQSubform.Form.Filter
 
you may try:

WhereCondition:= Me![SearchQSubform].[Form].[Filter]

//to slow.

but if your report uses different recordsource, that's another thing.
you need to remove the "form" reference from the filter string.
 
WhereCondition:= Me![SearchQSubform].[Form].[Filter]
Record source for both the sub-form and report are the same (SearchQ). I get the "Enter Parameter Value" popup box that asks for "SearchQSubform.Recipients" input. The column that is being filtered by the user is "Recipients".
 
WhereCondition:=Me.SearchQSubform.Form.Filter
I get the "Enter Parameter Value" popup box too with this code. It is asking for "SearchQSubform.Recipients" input. The column that is being filtered by the user is "Recipients".
 
like i said earlier, you need to "get rid" of the form reference from the filter:

Private Sub PrintPDF_Click()
Dim strCriteria As String
strCriteria = Trim$(Me![SearchQSubform].[Form].[Filter] & "")
If Len(strCriteria) Then
strCriteria = Replace$(Replace$(strCriteria, "[SearchQSubform].", ""), "SearchQSubform.", "")
Else
strCriteria = "(1 = 1)"
End If

DoCmd.OpenReport ReportName:="Report", View:=acViewReport, WhereCondition:=strCriteria
 
Private Sub PrintPDF_Click()
Dim strCriteria As String
strCriteria = Trim$(Me![SearchQSubform].[Form].[Filter] & "")
If Len(strCriteria) Then
strCriteria = Replace$(Replace$(strCriteria, "[SearchQSubform].", ""), "SearchQSubform.", "")
Else
strCriteria = "(1 = 1)"
End If

DoCmd.OpenReport ReportName:="Report", View:=acViewReport, WhereCondition:=strCriteria
That worked! Thank you! It prints the data when it's filtered and when it's not filtered. Brilliant! I am a novice with VBA, I would not have come up with this solution.
 

Users who are viewing this thread

Back
Top Bottom