Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Lowell is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Location
    Manitoba, Canada
    Posts
    54

    Mulitple word search in single field

    I have a recipe database that I need to be able to look up multiple ingredients to find a specific recipe.



    I have all the ingredients in one field.

    I would like to type: "Flour, Cajun, Fish" in a search box or multiple search boxes or something down that line.

    Then the query would bring up all the recipes which contain, at least, those three ingredients.
    (e.i. Southern Battered Cajun Fish, Louisianna Cajun Catfish, Southern French Entree,)

    I am certian this is possible, but I have run to a dead end on my trial and error.

    I have almost no talent in VBA.

    If VBA is the only way to do it, I will give it a try.

    Please help me if you can.

  2. #2
    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,848
    Please tell us more or show an example of this

    I have all the ingredients in one field.

  3. #3
    Lowell is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Location
    Manitoba, Canada
    Posts
    54
    Click image for larger version. 

Name:	Ingredient List.png 
Views:	21 
Size:	20.0 KB 
ID:	12848

    Here is a picture

  4. #4
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Are you wanting to do this in a query,a form or the table?

    Dale

  5. #5
    Lowell is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Location
    Manitoba, Canada
    Posts
    54
    I had thought I would type in the different ingredients in a query parameter box and it would bring up the info in the query.

    I had thought I would then use a form for the end user and run the form off of the query for an easy to use interface.

    What is your suggestion?

    As I mentioned earlier, I have run out of ideas on how to do what I want done.

  6. #6
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    I would use a form and VBA to build an SQL statement.
    Parameter box will work if you knew the exact length of the list. Like 5 or 6 ingredients.


    Dale

  7. #7
    Lowell is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Location
    Manitoba, Canada
    Posts
    54
    Well, that sounds like a good idea but I'm sorry, I have no idea where to start on writing VBA on a form.

    If you can at least get me started, I can see if I can blunder my way through.

  8. #8
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Well Lowell,
    The guy you need to talk to is orange.
    I may be able to stumble through it and get you something to work.
    However Orange will get you there faster and better looking code.

    I am not sure where to start myself.

    Dale

  9. #9
    Lowell is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Location
    Manitoba, Canada
    Posts
    54
    Okay thanks for your help,

    Orange, would you help me out?

  10. #10
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    Look this over.
    It will make you SQL list.
    I am trying to get it to show in a query or on a form.
    Put this in a form behind a command button.

    Code:
    Dim intIng As Integer
    Dim strSQL As String
    Dim strInger As String
    Dim strIngerTemp As String
    
    strInger = ""
    strSQL = ""
    
    For intIng = 1 To InputBox("End")
        strInger = InputBox("ingredient " & intIng & "; ")
        Select Case intIng
            Case Is = 1
                strIngerTemp = "ingredient = " & strInger
            Case Is > 1
                strIngerTemp = strIngerTemp & " AND ingredient = " & strInger
        End Select
        Debug.Print strIngerTemp
    Next intIng
    strSQL = "SELECT recipe, ingredient FROM YourTableName WHERE " & strIngerTemp
        Debug.Print strSQL
    'Get it into a query or form form here.
    Also needs error code.
    To see the debug.print, press ctl+G

    Dale

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Look at this tutorial for code that will build filter criteria from a multi-select list box http://allenbrowne.com/ser-50.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.

  12. #12
    Lowell is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2012
    Location
    Manitoba, Canada
    Posts
    54
    I tried that and everything I tried didn't work.

    The report and query mentioned in allen brownes website doesn;t exist in the three Northwind Sample databases I looked at so its kinda hard to figure out what I should do different with nothing to compare too.

    What happens now after following instructions to the best of my ablities is:

    I click the preview button and a little box that asks for comments comes up.
    I click ok and the report with all the info from the database is populated.

    I guess I need some more help

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    If you want to provide db with your attempted code 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.

  14. #14
    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,848
    Lowell,

    I tried that and everything I tried didn't work.
    That statement alone does not help you or the reader.
    Please be specific in telling us what you did exactly and what happened.
    Show us some code and data or screen shots; tell us the error message etc.
    Debugging with no information is impossible.

    I recommend you post your db as June7 has advised; and she'll review and comment.

  15. #15
    rzw0wr is offline I will always be a newbie
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Indiana
    Posts
    479
    try this,
    Code:
    Dim intIng As Integer
    Dim strSQL As String
    Dim strInger As String
    Dim strIngerTemp As String
     
    strInger = ""
    strSQL = ""
     
    For intIng = 1 To InputBox("End")
        strInger = InputBox("ingredient " & intIng & "; ")
        Select Case intIng
            Case Is = 1
                strIngerTemp = "ingredient = " & strInger
            Case Is > 1
                strIngerTemp = strIngerTemp & " AND ingredient = " & strInger
        End Select
        Debug.Print strIngerTemp
    Next intIng
    strSQL = "SELECT recipe, ingredient FROM YourTableName WHERE " & strIngerTemp
        ‘Debug.Print strSQL
    DoCmd.OpenReport "recipe", acViewPreview, , strSQL, acWindowNormal
    Dale

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

Similar Threads

  1. Searching for a single word in all table
    By rielcas in forum Access
    Replies: 1
    Last Post: 06-19-2013, 06:28 AM
  2. Replies: 1
    Last Post: 05-22-2013, 04:06 PM
  3. Search mulitple fields
    By wgroenewald in forum Forms
    Replies: 1
    Last Post: 02-23-2012, 11:46 AM
  4. Replies: 1
    Last Post: 01-30-2012, 12:12 PM
  5. Export single records to new Word Document
    By karmaimages in forum Import/Export Data
    Replies: 0
    Last Post: 11-19-2009, 03:37 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