Results 1 to 2 of 2
  1. #1
    accessnihon is offline Novice
    Windows XP Access 2003
    Join Date
    Oct 2011
    Posts
    10

    Filter for multiple criteria from a single textbox(in a form)

    Dear board members,

    after the very kind and prompt help I have received in the past, I would like to once more consult you over an issue I have while constructing my database.

    After (with your help) creating a form which enable me to filter for different, single criteria (one criteria per field), I also created a solution where I was able to filter one field for multiple, different criteria. However, the present solution is limited in multiple ways.

    The most important one is, that the solution is very static. The user can select 10different values through typing them into 10 different fields. However, he has to put exactly 10 values, as an error is returned if there are less values.
    Also, the maximum amount of values the user is able to filter for is ten, which might not be sufficient in the future.

    I would now like to build a solution, where the user is typing different values into one text field, and separates them with comas. Each of these values should then be set as a filter with wild cards.
    The necessity wildcards are also the reason I do not like a combo-box solution, as it would render it impossible, as far as I understand it.


    Any help would be highly appreciated. If there is anything you need to know, it would be my pleasure to support you with any necessary information



    Thank you very much in advance!

    tl,dr: I would like to create code that parses through coma separated values in one text field, and builds a filter list from this.
    Last edited by accessnihon; 12-04-2011 at 05:21 PM. Reason: addition

  2. #2
    accessnihon is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    10
    This is the code I have used for multi-criteria

    Code:
        If Me.m1.Value <> "" Then
    
            If Len(Trim(Nz(Me.m1, ""))) > 0 Then
            strFilter = strFilter & " AND " & "(" & "vehicletyp Like ""*" & Me.m1 & "*"" or "
            End If
         
            If Len(Trim(Nz(Me.m2, ""))) > 0 Then
            strFilter = strFilter & "vehicletyp Like ""*" & Me.m2 & "*"" or "
            End If
            
            If Len(Trim(Nz(Me.m3, ""))) > 0 Then
            strFilter = strFilter & "vehicletyp Like ""*" & Me.m3 & "*"" or "
            End If
            
            If Len(Trim(Nz(Me.m4, ""))) > 0 Then
            strFilter = strFilter & "vehicletyp Like ""*" & Me.m4 & "*"" or "
            End If
       
            If Len(Trim(Nz(Me.m5, ""))) > 0 Then
            strFilter = strFilter & "vehicletyp Like ""*" & Me.m5 & "*"" or "
            End If
       
            If Len(Trim(Nz(Me.m6, ""))) > 0 Then
            strFilter = strFilter & "vehicletyp Like ""*" & Me.m6 & "*"" or "
            End If
       
            If Len(Trim(Nz(Me.m7, ""))) > 0 Then
            strFilter = strFilter & "vehicletyp Like ""*" & Me.m7 & "*"" or "
            End If
       
            If Len(Trim(Nz(Me.m8, ""))) > 0 Then
            strFilter = strFilter & "vehicletyp Like ""*" & Me.m8 & "*"" or "
            End If
       
            If Len(Trim(Nz(Me.m9, ""))) > 0 Then
            strFilter = strFilter & "vehicletyp Like ""*" & Me.m9 & "*"" or "
            End If
       
            If Len(Trim(Nz(Me.m10, ""))) > 0 Then
            strFilter = strFilter & "vehicletyp Like ""*" & Me.m10 & "*"" AND "
            End If
    
            If Len(Trim(strFilter & "")) > 0 Then
            strFilter = Left(strFilter, Len(strFilter) - 5) & ")"
            End If
       
       End If
       Me.Filter = strFilter
       Me.FilterOn = True
    And this is how I imagine the future code to work:

    Code:
    Private Sub multi_Click()
    
    Dim strSearch As String
    Dim j
    
    strSearch = Split([Me.multit], [,])
    
    ...
    
    
            If Len(Trim(strSearch & "")) > 0 Then
            strSearch = Left(strSearch, Len(strSearch) - 5) & ")"
            End If
       
       End If
       Me.Filter = strSearch
       Me.FilterOn = True
    
    End Sub
    I am obviously lacking the complete middle part. I would guess, that I'll need to create a loop function, but am still a little bit stuck..

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

Similar Threads

  1. single form multiple database
    By sms2720 in forum Programming
    Replies: 7
    Last Post: 12-14-2011, 01:26 PM
  2. Replies: 1
    Last Post: 11-10-2011, 08:07 PM
  3. Replies: 1
    Last Post: 10-28-2011, 02:46 PM
  4. Single Form, Multiple Options
    By forrestapi in forum Forms
    Replies: 4
    Last Post: 06-30-2011, 07:09 AM
  5. Replies: 1
    Last Post: 02-03-2010, 08:17 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