Results 1 to 8 of 8
  1. #1
    doobybug is offline Advanced Beginner
    Windows 98/ME Access 2003
    Join Date
    Jan 2009
    Posts
    39

    Form to search using and/or parameters

    Hi,

    I am planning to have a form that acts as a query to search my table. I was thinking of doing the multiple fields and give the option to search by one or multiple fields along with the option to choose whether they want an AND criteria or an OR criteria. Ex: Search by name and surname
    Search name or surname

    Any ideas how I can achieve this? Maybe you can link me to an example?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    If you allow only one operator then should be simple. Multiple AND or multiple OR operators is easy. Mixing AND and OR could be really nasty.

    I have only done this once to allow OR operator. And never was satisfied with it.

    Revew http://www.allenbrowne.com/ser-62.html
    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.

  3. #3
    doobybug is offline Advanced Beginner
    Windows 98/ME Access 2003
    Join Date
    Jan 2009
    Posts
    39
    I have uploaded a picture of how I was thinking that the form should look like...I was going to include radio buttons or a check box for the and/or button. So you think I should abandon the idea?Click image for larger version. 

Name:	Sample.png 
Views:	18 
Size:	5.3 KB 
ID:	28773

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Mixing AND and OR operators gets complicated. Have to get parentheses just right.

    A AND B OR C

    is not the same result as

    A AND (B OR C)
    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.

  5. #5
    doobybug is offline Advanced Beginner
    Windows 98/ME Access 2003
    Join Date
    Jan 2009
    Posts
    39
    Thanks I will keep it in mind!! I understand what you are saying...I will try to avoid the OR then

  6. #6
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    If you use radio buttons, be sure to put them into an option group, otherwise you'll be able to select both. I was working on a db with a search form, but my intention was to have it much more robust than what you've shown. Alas, I got distracted by life (and maybe spending too much time here answering questions ) and haven't gotten back to it.

    What you want can work, but it requires a lot of thought and coding. As June7 implies (I think) and/or can be tricky but if you are not trying to nest them, prevent unsuitable choices from being made and don't allow conflicts then I think they should work fine. Search forms might function better if combo's are used instead of text boxes for certain fields so that garbage can't go into the search. A name field is probably not a good one for that. Once you have the design, the hard part comes. You have to concatenate criteria if there's more than one possibility and deal with situations where the first is supplied, but not the second (or vice versa) to avoid getting no results. You might also code for the possibility that incorrect data types are entered.

    Another method is to search as you type - filter the records displayed according to a search text box by using the OnChange event, but again, you'd have to concatenate the filter expression if it involves more than one field. That method allows the user to immediately see the result after each character is typed in since invalid criteria results in no records being displayed.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    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.

  8. #8
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,784
    Thanks June7. I suggest another step to try to curb the practice. Doobybug, please read:
    http://www.excelguru.ca/content.php?184

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

Similar Threads

  1. Expanding search parameters
    By Felwick in forum Access
    Replies: 4
    Last Post: 12-13-2016, 09:01 PM
  2. Replies: 16
    Last Post: 05-04-2014, 09:19 AM
  3. Replies: 7
    Last Post: 04-12-2014, 04:26 PM
  4. Query Parameters for Search Form
    By alsoto in forum Queries
    Replies: 7
    Last Post: 01-25-2012, 01:38 PM
  5. Search form with Two parameters
    By karanvemuri in forum Forms
    Replies: 11
    Last Post: 10-03-2011, 06:26 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