Results 1 to 12 of 12
  1. #1
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65

    2 Field Keyword Search


    Hi All,
    I'm attaching a database i'm having a little trouble with. Basically i want to have a keyword search on the form frm_BOSSearch but i can only get 1 search to work. I can search by name but when i try to add a search to another field the whole thing stops working. Anyone any ideas how i'd do this ?. I think i need to change the code in the query but not sure how to do it. I'd appreciate any help

    Thanks a lot
    Emma
    Attached Files Attached Files

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Have a continuous form with all records showing.
    Enter data into the 2 boxes (or 1 search box)
    then click the button.

    Code:
    sub btnFind_Click()
    dim sWhere
    
    if not ISNull(txtFind1) then sWhere = "[field1]='" & txtFind1 & "'"
    if not ISNull(txtFind2) then 
       if sWhere <> "" then sWhere = sWhere & " and "
       sWhere = "[field2]='" & txtFind2 & "'"
    endif
    
    me.filter = sWhere
    me.filterON = true
    end sub

  3. #3
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65
    Thanks Ranman...though i'm not sure how to make this work with what i already have....i'm using a ListBox in the example attached. The results change as i type. If i use your method can i then dispense with the query altogether ?

  4. #4
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    You don't need to use separate text fields for other search criteria. Use first one only and change your query to something like this:
    Click image for larger version. 

Name:	clip-query.jpg 
Views:	15 
Size:	208.6 KB 
ID:	23446

    You can add it to as many fields as you want but every next one will slow it down. Also if you'd like to search numeric fields as well you'll need to convert strings to numbers etc.

  5. #5
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65
    Thank you......i think that's the way i had it originally and it works fine up to a point. However, say i do a search by typing in a persons name and end up with a hundred records, how could i then narrow it down further ?

  6. #6
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Well, if you want separate searches for name/position/whatever then yes - use different search boxes as you do now and use references to them in your search query. Remember to put them in separate rows (as above) so they're OR not AND.

  7. #7
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65
    That's what i tried to do in the database attached but none of the search boxes work when i do it....there's some code in the OnChange event of the search boxes which might be the problem.
    (I got this code from someone else as i'm hopeless with VBA). I'm overlooking something when i'm adding the extra search boxes

  8. #8
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Code for search boxes looks OK and it should work if you set your query like this:
    Click image for larger version. 

Name:	clip-query2.jpg 
Views:	14 
Size:	157.9 KB 
ID:	23448

  9. #9
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65
    I set it up exactly as you suggested and none of the search boxes are working....not sure what i'm doing wrong

  10. #10
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Ok, two things:
    1. I was wrong, your search criteria should be set as ...AND... for what you want to achieve, so put them back in one row please
    2. I just opened your test database and nothing worked, I added button with simple msgbox and it didn't worked as well. Turned out database opened in disabled mode. To be precise it switched off all "dangerous" content such as vba events code. I had to switch it back on in "File" menu from ribbon and all works properly.
    Try it please and let me know if it works. You may want to add database file to trusted folders or something similar in options.

  11. #11
    Emma35 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Location
    Ireland
    Posts
    65
    Yes it works perfectly now....thank you very much for taking the time to help me. I appreciate it very much

    Emma x

  12. #12
    cyanidem's Avatar
    cyanidem is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2015
    Location
    Consett, UK
    Posts
    270
    Happy to help

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

Similar Threads

  1. KEYword search from a form field
    By Al77 in forum Forms
    Replies: 2
    Last Post: 03-30-2015, 12:43 PM
  2. Keyword or fragment search
    By orange in forum Sample Databases
    Replies: 0
    Last Post: 01-23-2015, 02:47 PM
  3. keyword search
    By Mbakker71 in forum Access
    Replies: 5
    Last Post: 02-05-2014, 06:03 AM
  4. keyword search in a combo box
    By pbouk in forum Forms
    Replies: 9
    Last Post: 05-30-2013, 09:45 PM
  5. Multiple Keyword Search
    By gatsby in forum Access
    Replies: 15
    Last Post: 01-21-2013, 10:53 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