Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

    Problem searching query


    I’m using Access 2013. I’m trying to search a query in 6 different fields. I’m using the “Like” feature in each field. If I only use 1 search field, it works fine. But, trying to search more than that brings up a problem. Access looks at the field and if it’s null, it disregards that field. So, searching for something in one field, the other fields also have to be populated or Access disregards it because it’s null. I need Access to look at all fields regardless of it being null. I was told that I need to use the Nz feature. I’m not sure how it works or if it will work. Any ideas?

  2. #2
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Can you show us your query at the present state?

  3. #3
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I'm not sure how to show the query. I'm new to forums. Here's the command in the criteria box: Like "*" & [Forms]![frmWeaponsSearch]![LastName] & "*"
    I'm using a form to do a search. The form is called [frmWeaponsSearch]. In that form, I fill out field and the query searches for what's in that field. If I only have one search, the process works like a charm. The problem is that I have multiple searches.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    In the query wizard where you built the query, switch to SQL view; copy the code you see and post it.

  5. #5
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Ok, I guess your query design looks similar to this:

    Click image for larger version. 

Name:	qr1.jpg 
Views:	10 
Size:	32.9 KB 
ID:	23784

    while it should look like this:

    Click image for larger version. 

Name:	qr2.jpg 
Views:	10 
Size:	36.2 KB 
ID:	23785

    But it's a pure guess as you didn't provide any useful info

  6. #6
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    Yes. It's like that except that I've used different names in the fields:

  7. #7
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

  8. #8
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I put them all in the same line of the criteria. I'm guessing I messed up on that.

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    When you put the criteria on the same line it is an AND of the criteria.
    On separate lines it is an OR of criteria.
    As Cyanidem said,you want the OR

    good luck.

  10. #10
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I put them on different lines. Now, it's showing everything regardless of what I try to search for.

  11. #11
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    That's why we need to see your query, without it we can only guess wasting our and your time.

  12. #12
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    What are you trying to accomplish

    1. Find all records where the entered critera match?
    2. Find all records where any of the entered criteria match?

    For instance if you put
    Mic
    Mou

    in your first name and last name and you have two people in your database

    Minnie Mouse
    Mickey Mouse

    If you use the AND (all the criteria are on the same line)
    and put in a criteria of

    MIC in your first name
    MOU in your last name both

    Only Mic(key) Mou(se) will be selected

    If you use the OR (all the criteria are on different lines)

    Mic(key) Mou(se)
    AND
    Minnie Mou(se)

    will be selected.

    If you are going to force a match on a null field you may have to do it with a formula similar to

    iif([Lastname] = forms!frmWeaponSearch!LastName or isnull(forms!frmWeaponSearch!LastName), 1, 0)

    Then use a criteria of 1 on this field

    Also note, if you are using LIKE on a date field or number field your query will fail.

  13. #13
    orange's Avatar
    orange is offline Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,725
    What exactly are you searching for? In which field/column would you find it?

  14. #14
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581

  15. #15
    UT227 is offline Expert
    Windows 7 32bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    581
    I'm searching by name, weapon type, serial number, ID number, and location. I want to be able to enter any one of the fields and get only the results for that search. I keep trying to post a jpg, but it hasn't shown.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. DAO ADO and Query for searching records
    By TioAdjie in forum Forms
    Replies: 12
    Last Post: 02-20-2014, 08:16 PM
  2. Replies: 22
    Last Post: 09-16-2013, 08:48 PM
  3. Searching Using a Query in Multiple Fields
    By RossIV in forum Queries
    Replies: 10
    Last Post: 07-24-2013, 06:32 AM
  4. Issue with searching and filtering query
    By federer8 in forum Queries
    Replies: 1
    Last Post: 02-08-2013, 06:21 PM
  5. Replies: 4
    Last Post: 06-29-2012, 09:05 AM

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