Results 1 to 3 of 3
  1. #1
    KyleMac is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Posts
    10

    Searching multiple fields in a table

    Edit: I now realize that's not my only problem with this setup. I'm trying to make it so the form will filter out any records that do not contain the filter set by item_in_a_textbox but the item could be in any of 10 fields.

    I've got a table with I1-I10 as fields and I was attempting to run a search through the fields for a specific word. I'm not sure what I'm missing but I can't get it to recognize a string.



    Code:
    do while i < 11
         istr = "I" & i
         if [istr] = me.item_in_a_text_box then
             strFilter = strFilter & "([istr] = """ & Item & """)"
         end if
         i = i + 1
    Loop
    Edit40: I fixed it by just putting 10 filters in (with a do while loop):
    Code:
    do while i < 11
         istr = "I" & i
             strFilter = strFilter & "([" & istr & "] = """ & Item & """) OR "
         end if
         i = i + 1
    Loop

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    The string will have to include every field name with OR operators. The fields are all text type? What is the actual name of the textbox?

    For i = 1 to 10
    strFilter = "[I" & i & "]=""" & Me.textboxname & """ OR "
    Next
    strFilter = Left(strFilter, Len(strFilter) - 4)
    Me.Filter = strFilter
    Me.FilterOn = True


    If only one of the 10 fields can have a value for each record, then this should be one field with 10 choices. If any or all of the 10 fields can have data, then really should be another related table.
    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
    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
    You may find the approach used in this search useful.

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

Similar Threads

  1. Replies: 36
    Last Post: 12-09-2013, 02:20 PM
  2. Searching Using a Query in Multiple Fields
    By RossIV in forum Queries
    Replies: 10
    Last Post: 07-24-2013, 06:32 AM
  3. Replies: 1
    Last Post: 04-12-2013, 03:03 PM
  4. searching for blank fields with a query
    By ironman in forum Queries
    Replies: 0
    Last Post: 03-04-2011, 03:48 PM
  5. Replies: 2
    Last Post: 05-25-2010, 02:45 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