Filter on sureport

P

p935754

I have a report named "eta1" with an independant subreport named "s_etat1"

I would like to filter my report with a filter that i build but I've got
error message when using the following code

Private Sub Commande0_Click()
On Error GoTo Err_Commande0_Click

Dim stDocName As String
Dim strFiltre As String

' Construction du filtre
strga = "A"
strFiltre = "([nom]='" & strga & "')"

' Ouverture formulaire
stDocName = "etat"
DoCmd.OpenReport stDocName, acPreview

' Lancement du filtre
With Reports![etat]![S_etat].Report
..Filter = strFiltre
..FilterOn = True
End With

Thank you for your help
 
A

Allen Browne

As you found, that won't work for a subreport. Access calls the subreport
multiple times (as many times as the main report's section has records), so
you cannot filter the subreport after it has been run.

You need to find a way to apply the filter beforehand. A common way to do
that is to create a form with a text box to hold the value. Then in the
query that supplies the records to the subreport, in the Criteria row, enter
something like this:
[Forms].[Form1].[nom]
Then each time the main report calls the subreport, it reads the value from
the form and limits its records to those that match.

This assumes that you can't just use the LinkMasterFields/LinkChildFields
properties.
 

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

Top