Results 1 to 9 of 9
  1. #1
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160

    how to write Where Condition to search for word in field

    Hi,
    I have a textbox - txtFilter - in the header section of continuous forms, in Events > AfterUpdate for txtFilter I've created a SetFilter macro to search the [Complaint] field on the continuous forms. What is the Where Condition to search for a word anywhere in this field?

    I've tried -
    Code:
    [Condition] like '*' & [txtFilter] & '*'
    but when I enter a word in txtFilter and press Enter I get a box to "Enter Parameter Value" for txtFilter.



    I want only those records that have the search term to appear in the continuous forms

    Any help appreciated
    David

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    If you want to search the Complaint field then why aren't you referencing it? Also need full form qualifier prefix.

    [Complaint] like '*' & Forms!formname![txtFilter] & '*'
    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
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    is this what you mean:
    Code:
    [Forms]![MempCompSF]![MempComplaintSubFrm].[Form]![Complaint] Like '*' & [Forms]![MempCompSF]![MempComplaintSubFrm].[Form]![txtFilter] & '*'
    This returns no records - no record found with filter term, even though there are records containing the term

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    There are two syntax structures for the WHERE CONDITION. Since this is a subform you want to filter, suggest using:

    Where Condition = ="[Complaint] LIKE '*" & [txtFilter] & "*'"
    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
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Thanks for this, been driving me nuts! Your suggestion about referencing and qualifier threw me.

    Ok this works great, one more question I would like to search 2 fields like so

    ="[Complaint] LIKE '*" & [txtFilter] & "*'" OR ="[EditedComplaint] LIKE '*" & [txtFilter] & "*'"

    Is this possible - if so what's the format?

    Thanks
    David


  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    ="[Complaint] LIKE '*" & [txtFilter] & "*' OR [EditedComplaint] LIKE '*" & [txtFilter] & "*'"
    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
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Perfect, thanks June, learnt alot!

    Marked Solved.

    As a matter of interest you say "there are two syntax structures for WHERE CONDITION" where's can I see exmple / documentation?

    David

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I did get ideas from web sources then exercised trial and error. Probably can't find them again. I search "Access macro SetFilter". I already show the two structures that worked for me. However, I tested the first one from post 2 on a solo form, not a subform, hence suggestion for second structure.

    I don't use macros, only VBA.
    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
    mdavid is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2017
    Posts
    160
    Ok Thanks, this was my first foray into Macros - seemed like a good idea, but now I think I'll stick to VBA as well.

    Thanks for all the help
    David

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

Similar Threads

  1. Replies: 1
    Last Post: 05-31-2016, 07:29 AM
  2. Replies: 9
    Last Post: 01-26-2015, 01:58 PM
  3. Replies: 15
    Last Post: 04-17-2014, 02:21 PM
  4. Mulitple word search in single field
    By Lowell in forum Queries
    Replies: 23
    Last Post: 06-28-2013, 09:32 PM
  5. Replies: 0
    Last Post: 05-17-2012, 09:24 AM

Tags for this Thread

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