Results 1 to 6 of 6
  1. #1
    DBDave is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2014
    Posts
    6

    How to construct a BuildFilter

    I'm trying to create a search form. The backend SQL table I need to search is partly denormalized. It contains 2 person name fields, something like [SalesmanName] and [ManagerName]. I have a union query which generates a list of all names (without dupes) including Salesmen and Managers because I don't care which of the two fileds contains the name being searched for. The user selects a name from a unbound combobox which has the union query as it's row source.

    The code for my search form sets a RecordSource as in the following common example:


    Me.RecordSource = "SELECT * FROM qrySearch " & BuildFilter

    If I want to construct BuildFilter as a "Like" clause, that's a piece of cake. There are a number of examples that show how to do that. However, I want to construct a BuildFilter with an equality ("="), and also using "or" operator? In pseudo-code, that looks like the following:

    "If the comboxbox value is not blank find rows where [SalesmanName] equals the combox value OR [ManagerName] equals the comboxbox value"

    I'm stuck on constructing that statement. All my attempts at that syntax are blowing up with compile errors or syntax errors. Can you help me out? I would greatly appreciate it!

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    This example should help you. If not, post back and ask more questions.

    http://www.allenbrowne.com/ser-62code.html

  3. #3
    DBDave is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2014
    Posts
    6
    Quote Originally Posted by ssanfu View Post
    This example should help you. If not, post back and ask more questions.

    http://www.allenbrowne.com/ser-62code.html
    Great examples in that article. Thanks!

  4. #4
    DBDave is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2014
    Posts
    6
    Quote Originally Posted by ssanfu View Post
    This example should help you. If not, post back and ask more questions.

    http://www.allenbrowne.com/ser-62code.html
    Can I follow up with a related question? I set up the filtering on a search form and now it's working with help of that Allan Browne article. I want the user to click a button and open a report based on the same filter. What's the best approach to that? Do I have to recreate the same filter function in an event on the report? Can the report refer to the BuildFilter in the form? Thanks.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    Instead of (or in addition to) setting the form filter property, pass the filter criteria to report when it opens:

    DoCmd.OpenReport "report name", , , strWhere

    If you want separate button for opening report, then put Allen Browne's code into a Sub behind the form that can be called by both buttons.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    DBDave is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2014
    Posts
    6
    Quote Originally Posted by June7 View Post
    Instead of (or in addition to) setting the form filter property, pass the filter criteria to report when it opens:

    DoCmd.OpenReport "report name", , , strWhere

    If you want separate button for opening report, then put Allen Browne's code into a Sub behind the form that can be called by both buttons.
    Great. I'll try it tonight.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 09-17-2014, 05:12 PM
  2. Replies: 1
    Last Post: 08-15-2014, 01:55 PM
  3. Replies: 7
    Last Post: 07-19-2014, 05:54 AM
  4. Replies: 5
    Last Post: 04-23-2013, 01:42 PM
  5. BuildFilter
    By warrenjburns in forum Forms
    Replies: 2
    Last Post: 04-07-2009, 11:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums