Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    noobaccess is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    22

    Search fields SQL

    Hi,

    Anyone know how i can write a SQL query based on search fields? i want to do up a search form that i can search for items that will narrow down the things i want to search. i've been trying to figure it out but my SQL query doesnt seems to work.

    Your help will be greatly appreciated!!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Review tutorials at http://datapigtechnologies.com/AccessMain.htm

    Especially section Access Forms: Tips and Techniques:
    Look the items:
    Build a Custom Filter in Your Form

    Creating a Basic Search Form
    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
    noobaccess is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    22
    oh! thanks!

    however, is it possible to search for values that are in a listbox? Like i have a table with a field that stores multiple data in a single field. for example, there are values stored in the table column called toys, which the values are dolls, cars, machines. if i search cars in my listbox, can it show that row of values?

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Like i have a table with a field that stores multiple data in a single field.
    This indicates a relational design problem.

    see
    http://forums.aspfree.com/attachment...2&d=1201055452

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    If these are multi-value fields then no, at least not easily. I never use multi-value fields. http://office.microsoft.com/en-us/ac...001233722.aspx

    If the data is just a string of comma separated text then yes, it is possible. The example in the tutorial is applicable. Although the wildcard would have to be on both sides of the criteria: Like "*" & [critiera input] & "*"
    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
    noobaccess is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    22
    Although the wildcard would have to be on both sides of the criteria: Like "*" & [critiera input] & "*"

    Oh!! this works well together with the link that you have given me at #2 !

    Really thank you all very much!!!!!

  7. #7
    noobaccess is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    22
    hi sorry can i ask another question?

    i was asked to do "ALL" search textbox where i can search for anything in the textbox but i tried using ( Like [Forms]![Prospect Table search]![Search] & "*" ) but it doesnt work..

    any idea if i have done something wrong or i am not suppose to use this query statement?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Why doesn't work - error message, wrong results, nothing happens?

    What field is that criteria under?

    You have only the one wildcard. That means the input string must be at beginning of the values.
    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
    noobaccess is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    22
    Actually i m not sure what field it should be under, i thought i shld have all the column name under that criteria so i tried using a wildcard but it doesnt seems to work. i tried putting all the column name under the criteria but it still doesnt work.

    it shows an error message when i use the wildcard.. can you take a look at it ?

    Click image for larger version. 

Name:	error.jpg 
Views:	5 
Size:	43.5 KB 
ID:	10268

    Click image for larger version. 

Name:	error2.jpg 
Views:	6 
Size:	41.9 KB 
ID:	10269

    this is my query.. is it wrong?

    i tried this too! but it doesnt work..

    Click image for larger version. 

Name:	error3.jpg 
Views:	6 
Size:	39.7 KB 
ID:	10270

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Comply with the error popup. Remove the criteria from the * column. The criteria for the other fields need to be on separate OR rows. The resulting appearance will be stair-steps. As it is the AND operator is in effect which means the criteria value must be found in ALL fields for record to return.

    Uncheck the search fields so the query won't have duplicates of the fields. The search will still work, those columns just won't show.
    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
    noobaccess is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    22
    hmmm... but if i were to use OR everything in my search results will be messed up.. i just tried, it doesnt work however if i were to use AND it works perfectly fine. but the search textbox that i want to search for anything doesnt work..

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Then I don't understand what you want.

    I tested a query that referenced one textbox as criteria for multiple fields. I tested both AND and OR operators. The OR worked properly and the AND failed.

    Do you want both a general input textbox that will be criteria for all fields as well as specialized textboxes as criteria for respective fields? Mixing AND and OR operators is messy and frustrating.
    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.

  13. #13
    noobaccess is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    22
    yes i understand that! Search field is very frustrating!

    hmm ok .. i am actually trying to search for records that will allow me to displays my the items that i want to search. currently i have 4 drop down list and 1 multi purpose search textbox that allows me to search for anything.

    Is using OR better? Because i followed the video you show me the other time and it was using AND

    this is how the OR should look like right?
    Click image for larger version. 

Name:	error4.jpg 
Views:	7 
Size:	38.3 KB 
ID:	10271

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    The video uses AND because each field has different criteria reference.

    The image shows not all criteria with LIKE and wildcard.
    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.

  15. #15
    noobaccess is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Nov 2012
    Posts
    22
    for price point i could not use wildcard or LIKE because that search field is use to search for points(numeric) that are below a certain number....

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

Similar Threads

  1. Search mulitple fields
    By wgroenewald in forum Forms
    Replies: 1
    Last Post: 02-23-2012, 11:46 AM
  2. Fields get saved in DB when I search!
    By accessnewb in forum Programming
    Replies: 2
    Last Post: 07-25-2011, 09:44 AM
  3. Search across multiple fields
    By Nexus13 in forum Programming
    Replies: 2
    Last Post: 07-08-2011, 02:38 PM
  4. Help with Search Fields
    By jhawk in forum Forms
    Replies: 2
    Last Post: 03-16-2011, 08:42 AM
  5. Help with Search Fields
    By jhawk in forum Programming
    Replies: 0
    Last Post: 03-15-2011, 08: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