Filtering a Subreport from a form...

pretogues

New member
Local time
Today, 09:10
Joined
Aug 25, 2012
Messages
7
Hi, everybody.

Well, I think what i will ask you is something that I'm looking for an answer, but i didnt' find it till now. And I know this is not a new question but...

I have a form that includes some text boxes and combo boxes. The user fills these controls to build a report based on that group of criteria. on this form there is a button where i'm building a VBA code on the click_button command.

The report has one subreport. They are perfectly linked and when the user chooses a textbox or a combox refering to main report, the filter works ok.
The problem is with the controls that try to filter the subreport.

The reports don't have a query.

And this is the code i'm building:

Private Sub botrel_Click()
On Error GoTo Err_botrel_Click

Dim stDocName As String
Dim strWhere As String
Dim lngLen As Long

' this one works perfectly (it refers to the main report)
If Not IsNull(Me.ProNum) Then
strWhere = strWhere & "([ProNum] Like ""*" & Me.ProNum & "*"") AND "
End If


' This one is my problem:
' I verified all the names of the reports, the are correct!!!

If Not IsNull(Me.imovnat) Then
strWhere = strWhere & "(Reports![Rel_Pro - teste]![Tbl_Hip subrelatório].Report![HipNatBem]= """ & Me.imovnat & """) AND "
End If



' I know that on the final condition i'm adding criteria for the main report
' and for the subreport and i think this is the point!!!

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
Response = MsgBox("You choose any criteria. Would you like to continue?", vbOKCancel)
If Response = vbCancel Then End
Else
strWhere = Left$(strWhere, lngLen)
End If
stDocName = "Rel_Pro - teste"
DoCmd.OpenReport stDocName, acPreview, , strWhere

Exit_botrel_Click:
Exit Sub

Err_botrel_Click:
MsgBox Err.Description
Resume Exit_botrel_Click

End Sub


Can anybody help?
By the way, this is made in ACCESS 2003.
Please, forgive me for my english. it's not quite good!!!

Best regards
 
I don't believe that uou can modify a subreport the way your attempting to do same.

Modify the subreports' recordsource (query) before openng the report.
 

Users who are viewing this thread

Back
Top Bottom