Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    omair1051992 is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    11

    Multi-Field Search Query not working

    Hello,



    I used a Youtube video tutorial to make a multi-field search query. I have a form for navigating the records in my table. I made a similar form (with same text boxes i.e fields) called SearchForm. I want my query to search for records in the table that match the entries in the SearchForm. I have copied this code into the all fields in the form

    Like "*" & [Forms]![SearchForm]![<<particular field>>] & "*"

    The query shows a blank return, no matter what has been entered into the SearchForm. What should I do?

    Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    Want to provide the db for analysis? Follow instructions at bottom of my post.
    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
    omair1051992 is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    11
    There you go, I have attached the database.

    Mod Edit: Remove attachment because appears to have real personal data.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    Second time this week I've seen this same issue.

    Problem is with Null fields. If you require a value in every field then this issue will not happen. Can populate with NA or whatever you like if no data provided. Otherwise, need to handle the Nulls in the query. Each field where Nulls are allowed will require an expression, like:

    Middle: MiddleName & ""

    Then apply the input parameter to the constructed field. The constructed fields do not have to be visible. The native fields can still be included in the query and controls bound to them.
    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
    omair1051992 is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    11
    I'm sorry but I do not quite understand how I am supposed to work that out. I do not require a value in every field; even if just one or two fields are filled out then the query should just filter using those.

    What exactly should I change in this code, if each and every single field is allowed to have null value:
    Like "*" & [Forms]![SearchForm]![FirstName] & "*"

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    Yes, but unfortunately null interferes.

    The parameter does not need to be changed. My instructions are to create fields with an expression like the one in my previous post that handle possible null and put the parameters under those constructed fields. The suggested expression will insure that every value is a string, even an empty string, and not a null.
    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.

  7. #7
    omair1051992 is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    11
    I'm sorry but I am a complete novice in Access when it comes to these kinds of stuff. Where should I enter 'Middle: MiddleName & ""', and what exactly should I change to my table/query/form or whatever?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    Creating fields with expression in query is basic Access functionality. Review http://office.microsoft.com/en-us/ac...#_Toc288566554

    So you need to use the query designer grid and:

    1. create the Middle field with the expression: MiddleName & ""

    2. put criteria parameter under the constructed field
    Like "*" & [Forms]![SearchForm]![MiddleName] & "*"
    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.

  9. #9
    omair1051992 is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    11
    I entered {FirstName: [FirstName] & ""} in the Field row of the query designer and Access gives an error 'Circular reference caused by alias 'FirstName' ...'

    I entered {FirstName & ""} in the Field row. It automatically turns into {Expr1: [FirstName] & ""} but shows up each and every record when the query is run, no matter what values are entered in the SearchForm. The parameter is still the same.

    I know how to make basic expressions for calculations but this is completely beyond me. I have attached the database for analysis again, with fake data.
    Attached Files Attached Files

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    To avoid circular reference is why I used Middle as the name for field constructed with expression: MiddleName & "". You can use whatever you want in place of the generic Expr1, Expr2, etc or just leave them that way. Your Query2 seems to work just fine for me.
    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.

  11. #11
    omair1051992 is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    11
    I changed the name fields to just First, Middle and Last and the circular reference error is handled. Query2 still doesn't work for me, showing up all the records regardless of what values are entered in the SearchForm.

  12. #12
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    Not sure, if this is what you are looking for.
    Just check the search form in db
    DB_1.zip
    attached.

    Thanks

  13. #13
    omair1051992 is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    11
    I don't really see any difference. The queries are still the same and don't work at all.

  14. #14
    recyan's Avatar
    recyan is offline Expert
    Windows 2K Access 2000
    Join Date
    Dec 2011
    Posts
    662
    1) The search query is now based on Query1.
    2) Did you try using the search form, if yes what was the result ? For eg. If you enter lily in first name field in the form, what was the result ?

    Thanks

  15. #15
    omair1051992 is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Jun 2012
    Posts
    11
    Query1 doesn't contain any parameters in the criteria, just the fields and the table name.

    When I enter Lily in the SearchForm, Query1 and SearchQuery2 show all the records. SearchQuery doesn't show any records. SearchQuery3 has circular reference error.

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

Similar Threads

  1. Multi-value Text Field Search
    By billfold in forum Queries
    Replies: 3
    Last Post: 04-30-2012, 03:43 PM
  2. Multi Field Combo search Form
    By Andyjones in forum Access
    Replies: 3
    Last Post: 03-12-2012, 02:13 PM
  3. Access 2010 - search query not working
    By beetgirl in forum Access
    Replies: 6
    Last Post: 07-12-2011, 09:56 PM
  4. Replies: 9
    Last Post: 05-05-2011, 02:05 PM
  5. Search field is not working correctly
    By jakeao in forum Programming
    Replies: 9
    Last Post: 05-18-2009, 07:47 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