Results 1 to 10 of 10
  1. #1
    2 Star Lounger
    Join Date
    Nov 2002
    Location
    Mt. Olive, North Carolina, USA
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Filter report with OR (2000)

    I am trying to open a filtered report that has an OR in the VBA code. Here is where I am at now with the code and I get a type mismatch.
    Dim stDocName as String
    Dim stFilter as String
    stFilter = "flag =" & chr(34) & "a" & chr(34) OR "flag =" & chr(34) & "m" & chr(34)
    stDocName = "SomeReport"
    Docmd.OpenReport stDocName, acPreview, ,stFilter
    Thank you for your help in advance.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Filter report with OR (2000)

    I assume that the OR is part of the condition, so it should be within the quotes:
    <code>
    stFilter = "flag =" & Chr(34) & "a" & Chr(34) & " OR flag =" & Chr(34) & "m" & Chr(34)</code>

  3. #3
    2 Star Lounger
    Join Date
    Nov 2002
    Location
    Mt. Olive, North Carolina, USA
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Filter report with OR (2000)

    Hans, when I tried that code it returns all records. If I just use the first part to select the records where flag = a, all the records that flag = a are selected so the first part will work. Selecting records where flag = a or m is not working. Is there something else I can try to see why your code does not work???

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Filter report with OR (2000)

    Please try to explain what exactly you want to accomplish. And, if possible, attach a stripped down copy of your database. See <post#=401925>post 401925</post#> for instructions.

  5. #5
    2 Star Lounger
    Join Date
    Nov 2002
    Location
    Mt. Olive, North Carolina, USA
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Filter report with OR (2000)

    I would like to preview a report that only has the records where flag = a or m. Attached is a database for you to look at.
    Thank you for your help.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Filter report with OR (2000)

    In your first post in this thread, you opened the report using the instruction
    <code>
    DoCmd.OpenReport stDocName, acPreview, , stFilter
    </code>
    In the database you attached, you have changed it to
    <code>
    DoCmd.OpenReport stDocName, acPreview
    </code>
    In other words, you have omitted the WhereCondition argument, so all records are displayed. If you restore the correct intruction, the records will be filtered as intended.

  7. #7
    2 Star Lounger
    Join Date
    Nov 2002
    Location
    Mt. Olive, North Carolina, USA
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Filter report with OR (2000)

    OOOPSSS. Sorry about that. When I created the sample database I omitted the filter. It does indeed work for this sample database. I will have to go back to the real database to see what I am missing and play with it some more. On the surface it looks to be the same code. Thank you for your patience and help.

  8. #8
    2 Star Lounger
    Join Date
    Nov 2002
    Location
    Mt. Olive, North Carolina, USA
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Filter report with OR (2000)

    OK. I got it to work. It looks like I have to save the form before the new code will run. Is this true?
    On a related note. If I want to preview the filtered report then preview all records, What do I need so the code continues to run after I close previewing the filtered report?
    DoCmd.OpenReport stDocName, acPreview, , stFilter
    DoCmd.OpenReport stDocName, acPreview
    Thanks again.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Filter report with OR (2000)

    In Access 2002 and higher, you can open a report as modal, i.e. code execution pauses until the report is closed, but Access 2000 doesn't have this feature. I think you'll have to provide two separate command buttons: one to open the filtered report, another one to open the unfiltered report.

  10. #10
    2 Star Lounger
    Join Date
    Nov 2002
    Location
    Mt. Olive, North Carolina, USA
    Posts
    170
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Filter report with OR (2000)

    OK. I will do that.
    Have a great night.
    Thanks again.

Posting Permissions

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