Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2003
    Posts
    233

    Unanswered: filter reports using the Report_Open event

    i tried Me.Filter="Country='USA'" in my Report_Open event, and it didnt work, how can i filter, using this event with a hard coded value?

    i dont want to set the filter in a form and then open, sounds stupid but this is what i need to do

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Using the me.Filter in a report requires the report to be open to apply the filter (I don't think you can do this on the Report OnOpen event.) Another ideal option is to open the report with criteria:

    DoCmd.OpenReport "MyReportName", acViewPreview, , "[Country] = 'USA' "
    or
    DoCmd.OpenReport "MyReportName", acViewPreview, , "[Country] = ' " & Forms!MyCriteriaForm!MyCriteriaField & " ' "
    Last edited by pkstormy; 11-20-07 at 11:55.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    "[Country] = ' " & Forms!MyCriteriaForm!MyCriteriaField & " ' "
    Just to be picky there are 2 extra white spaces in your criteria... Should read
    Code:
    "[Country] = '" & Forms!MyCriteriaForm!MyCriteriaField & "' "
    George
    Home | Blog

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    I put the spaces in there George to show the difference between the " and ' (too lazy I guess to change the colors.)
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Sorry Paul, shouldn't have pointed out. After all, code that works straight from the copy paste means the OP won't be learnig anything, eh?


    Friends?
    George
    Home | Blog

  6. #6
    Join Date
    Nov 2003
    Posts
    1,487
    Why you want to do this is beyond me. What's the difference from placing the Filter directly into the Filter Property and placing the code to do so especially if you're placing the the criteria data directly into place? Well to each their own, I'm sure you have your reasons. So onward we go....

    Well Mike....It does Work (in Access 2000 and 2002 anyways). You just forgot one simple thing. You forgot to turn the Filter ON with the FilterOn property.

    Your code should look like this:

    Code:
    Private Sub Report_Open(Cancel As Integer)
      Me.Filter = "[Country]='USA'" 
      Me.FilterOn = True
    End Sub
    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •