Results 1 to 11 of 11
  1. #1
    Njliven is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    86

    Filter with Keyword in Memo Field


    I need help in figuring out the best way to go about creating a way to filter a form based on a keyword in a memo field. I want the user to be able to click on a button and enter the keyword they want and then the records will filter and show all the records containing that particular keyword. Thanks for any help!

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Why is this in a memo field? Please tell us more.

    You may get some ideas from this keyword search.

  3. #3
    Njliven is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    86
    Quote Originally Posted by orange View Post
    Why is this in a memo field? Please tell us more.

    You may get some ideas from this keyword search.

    It is a memo field because it has a large amount of data concerning a project description and scope. The user needs to be able to find a specific word so they can find all the projects with all the same type data they are looking. This can be a wide variety of things.

  4. #4
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Have you tried instr([Memo_field],keyword) > 0 ? (with your own variable and field names)
    Last edited by John_G; 05-12-2016 at 12:26 PM. Reason: Arguments were reversed in the Instr

  5. #5
    Njliven is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    86
    It does not like the > sign, it says an = is expected. Also I am not sure how to make the variable so the user can input what they want to search. Does this code go in the buttons on click event?

  6. #6
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    You would have to use VBA to create a filter string, then re-filter the form. Suppose the textbox is called SearchWord; if you have a button to perform the search / filter, you could put something like this in the On_Click:

    Code:
    Dim FilterString as String
    
    FilterString= "Instr([Memo_field]),'" & me!SearchWord & "' ) > 0"
    docmd.applyfilter , FilterString

  7. #7
    redbull's Avatar
    redbull is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Mar 2012
    Location
    Missouri
    Posts
    480
    So on the button onclick, if you just want the user to be able to put in a Keyword or search term... and don't want a fancy form...


    Dim Keyword as string

    Keyword = inputbox("Please enter your keyword")

    If instr([Memo_field],keyword) > 0 then
    run whatever query you want with the keyword in it. Because it has a result.
    else
    msgbox "Didn't find a match"
    End if

    Or if you have a textbox on the main form, with a button... instead of the input box.. just

    Keyword = me.forms.txtbox.value, or something like that.

  8. #8
    Njliven is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    86
    To: John_G
    With this code I am getting a run time error. When I click to debug it has the last line highlighted
    DoCmd.ApplyFilter , FilterString. I tried a couple of different things, but then when I click the button nothing happens.
    What to do next?

  9. #9
    Njliven is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    86
    To redbull,
    With this code you say I need a query, but I want to filter the form and bring back all the records with the entered keyword. Can this be done with a button only?

  10. #10
    Njliven is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2012
    Posts
    86
    I found a solution. I had two memo fields and I was going to make a button for each one, but I found code that would search and filter both fields and this is perfect for my situation. I added it to the buttons on click event and it works perfectly.

    Dim MyValue As String
    MyValue = InputBox("Enter Keyword")
    Me.Filter = "[Memo_Field1] Like '*" & MyValue & "*' Or [Memo_Field2] Like '*" & MyValue & "*'"
    Me.FilterOn = True

  11. #11
    orange's Avatar
    orange is online now Moderator
    Windows 8 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Not sure what you have for data, but here is a sample from one of my tables. It uses the INSTR() construct suggested to you by the others.

    I'm doing this with a query, but you could set up a form with similar concept. I have used " employee" as my keyword for this sample. You could use a txtbox to create your filter.

    I am searching for a keyword/string within a memo field called "txt".
    If found I return the Estblmt_No, the length of the memo field, the right most 20 characters of the memo field, and the momeo field.

    Code:
    SELECT tbl_Spl_LCL_Std_EstProfileEng.ESTBLMT_NO
    , Len([TXT]) AS LENGTH
    , Right([txt],20) AS Last20
    , tbl_Spl_LCL_Std_EstProfileEng.txt
    FROM tbl_Spl_LCL_Std_EstProfileEng
    WHERE  instr(txt, " employee")>0
    OOOPs: I see you have resolved it while I was typing.
    Attached Thumbnails Attached Thumbnails queryMemoFieldForKeyword.jpg  

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

Similar Threads

  1. 2 Field Keyword Search
    By Emma35 in forum Forms
    Replies: 11
    Last Post: 01-19-2016, 08:34 AM
  2. KEYword search from a form field
    By Al77 in forum Forms
    Replies: 2
    Last Post: 03-30-2015, 12:43 PM
  3. Replies: 9
    Last Post: 07-21-2014, 11:57 AM
  4. Replies: 5
    Last Post: 01-30-2014, 10:55 AM
  5. Replies: 24
    Last Post: 06-14-2013, 03:13 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