Trouble with WITH... and report

Notiophilus

Registered User.
Local time
Today, 14:46
Joined
Jan 18, 2015
Messages
42
Access 2010. I have a subform which dynamically shows either a form or a report. On the main form there is a button to clear the recordset and filters of each, and for clarity's sake I used a with... end with statement. Access disnae like it.

With the form, this works:
Code:
If Me.fsubContainer.SourceObject = "fsubBrowseAll" Then       
        
        ' some stuff here
        With Me.fsubContainer.Form
            .RecordSource = "tblStory"          ' Clear recordsource
            .Filter = "(False)"                 ' and hide ALL records
            .FilterOn = True
        End With
But this doesn't:
Code:
    ElseIf Me.fsubContainer.SourceObject = "Report.rptStories" Then
        With Me.fsubContainer.Report
            .RecordSource = "tblStory"          ' Clear rs and show all records
[B]            [COLOR=Red].Filter = ""                        ' ##Run-time error 5: invalid procedure or argument[/COLOR][/B]
            .FilterOn = True
        End With

    End If
This, however, does:
Code:
        Me.fsubContainer.Report.RecordSource = "tblStory"
[COLOR=SeaGreen] [B]       Me.fsubContainer.Report.Filter = ""                 [/B]
[/COLOR]        Me.fsubContainer.Report.FilterOn = True
confused.gif
Why? Is this just inconsistency in Access, or might it be a sign of a deeper problem in the code? (For whatever reason, the last statement gave several errors until I changed Report.Filter = "(False)" to .Filter = "", so I don't know if it's just that reports are rather touchy)
 
Have you tried, (I know it was not what you asked about):
Code:
  ElseIf Me.fsubContainer.SourceObject = "Report.rptStories" Then
    With Me.fsubContainer
      [B][COLOR=Red].Report[/COLOR][/B][COLOR=Red][COLOR=Black].[/COLOR][/COLOR]RecordSource = "tblStory"
      [B][COLOR=Red].Report[/COLOR][/B].Filter = ""
      [B][COLOR=Red].Report[/COLOR][/B].FilterOn = True
    End With
  End If
 
you wouldnt filter in a report. The query does the 'filtering'

and you wouldnt set the filter = "", instead just turn it off...
FilterOn = false
 
Have you tried, (I know it was not what you asked about):
Code:
  ElseIf Me.fsubContainer.SourceObject = "Report.rptStories" Then
    With Me.fsubContainer
      [B][COLOR=Red].Report[/COLOR][/B][COLOR=Red][COLOR=Black].[/COLOR][/COLOR]RecordSource = "tblStory"
      [B][COLOR=Red].Report[/COLOR][/B].Filter = ""
      [B][COLOR=Red].Report[/COLOR][/B].FilterOn = True
    End With
  End If

That seems to have done it. Thanks!

@Ranman - but reports do have a filter function. Why not use it?
By having both recordsource query and filter I can toggle the filter on and off without performing the query again. (Filtered fields are those I might want to toggle - let's say whether I own a book or not. I can search for [books in category A] [that I own] and switch to [books in category A][all] without a requery.) Scratch that - I also realised I was missing a .Report.Requery as otherwise it won't update, which probably makes the whole "not requerying" thing moot.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom