Results 1 to 5 of 5
  1. #1
    gsimmons77 is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2009
    Posts
    2

    Exclamation Search form with results in subform view--Problems with code!

    Hello--------

    I am trying to create a search form in Access. I have the following “unbound” fields:

    Project Number as a text box
    ARRA Number as a text box
    State Number as a text box
    County as a multi-select box with 96 possible selections
    Region as a multi-select box with 4 possible selections
    Project Type as a multi-select box with 24 possible selections


    Everything is set to text. I’ve seen this work with bound and unbound fields. Since this is unbound, I’ve told Access where I want to pull from. You’ll see that in the code.

    Here’s where the code is breaking. I am receiving the following error: Run time error 5, Invalid Procedure call or argument.

    The following is the procedure with the error in RED-------

    'If County
    If Me!County.ItemsSelected.Count > 0 Then
    strFilter = strFilter & "("
    For Each varItem In Me!County.ItemsSelected
    strFilter = strFilter & "qryMetrics.[County Name]=" & Chr(34) & Me!County.ItemData(varItem) & Chr(34) & " OR "
    Next
    strFilter = Left$(strFilter, Len(strFilter) - 97) & ") And "
    End If

    'If Region
    If Me!Region.ItemsSelected.Count > 0 Then
    strFilter = strFilter & "("
    For Each varItem In Me!Region.ItemsSelected
    strFilter = strFilter & "qryMetrics.[Region]=" & Chr(34) & Me!Region.ItemData(varItem) & Chr(34) & " OR "
    Next
    strFilter = Left$(strFilter, Len(strFilter) - 5) & ") AND "
    End If

    'If Project Purpose
    If Me!ProjectPurpose.ItemsSelected.Count > 0 Then
    strFilter = strFilter & "("
    For Each varItem In Me!ProjectPurpose.ItemsSelected
    strFilter = strFilter & "qryMetrics.[Project Purpose]=" & Chr(34) & Me!ProjectPurpose.ItemData(varItem) & Chr(34) & " OR "
    Next
    strFilter = Left$(strFilter, Len(strFilter) - 25) & ") AND "
    End If

    'If Status
    If Me!Status.ItemsSelected.Count > 0 Then
    strFilter = strFilter & "("
    For Each varItem In Me!Status.ItemsSelected
    strFilter = strFilter & "qryMetrics.[Status]=" & Chr(34) & Me!Status.ItemData(varItem) & Chr(34) & " OR "
    Next
    strFilter = Left$(strFilter, Len(strFilter) - 4) & ") AND "
    End If

    'If Employees
    If Me!Employees.ItemsSelected.Count > 0 Then
    strFilter = strFilter & "("
    For Each varItem In Me!Employees.ItemsSelected
    strFilter = strFilter & "qryMetrics.[EmployeeID]=" & Chr(34) & Me!Employees.ItemData(varItem) & Chr(34) & " OR "
    Next
    strFilter = Left$(strFilter, Len(strFilter) - 30) & ") AND "
    End If

    If strFilter <> "" Then


    strFilter = Left$(strFilter, Len(strFilter) - 10)
    End If

    If strFilter = "" Then
    Me!sfrmSearch.Form.FilterOn = False
    Else
    Me!sfrmSearch.Form.Filter = strFilter
    Me!sfrmSearch.Form.FilterOn = True
    End If

    End Sub

    __________________________________________________ ______________________

    Function GetDateFilter(dtDate As Date) As String
    ' Date filters must be in MM/DD/YYYY format
    GetDateFilter = "#" & Format(dtDate, "MM/DD/YYYY hh:mm:ss AM/PM") & "#"
    End Function


    I have been racking my brain on this one. Thank you to anyone who can assist!!!!!!

    GSimmons

  2. #2
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows XP Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    I think but not 100% sure.

    strFilter = Left$(strFilter, Len(strFilter) - 97) & ") And "

    Should be

    strFilter = Left$(strFilter, Len(strFilter) - 97)) & " And "

  3. #3
    gsimmons77 is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2009
    Posts
    2
    Quote Originally Posted by Rainlover View Post
    I think but not 100% sure.

    strFilter = Left$(strFilter, Len(strFilter) - 97) & ") And "

    Should be

    strFilter = Left$(strFilter, Len(strFilter) - 97)) & " And "
    Hey Rainlover,

    Thank you so much for the response! I tried the recommendation, and unfortunately, it didn't work. Any ideas?
    Greg

  4. #4
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Have you tried removing that "$" from the function name?

  5. #5
    Rainlover's Avatar
    Rainlover is offline Expert
    Windows XP Access 2003
    Join Date
    Nov 2009
    Location
    Queensland Australia
    Posts
    691
    Sorry about that.

    You do not have matching opening and closing brackets.

    Try

    strFilter = Left$(strFilter, Len(strFilter) - 97) & " And "

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

Similar Threads

  1. Subform results
    By terryvanduzee in forum Forms
    Replies: 1
    Last Post: 10-13-2009, 07:52 PM
  2. search,view and open function
    By blurboy84 in forum Reports
    Replies: 0
    Last Post: 10-08-2009, 11:42 PM
  3. Replies: 16
    Last Post: 09-23-2009, 08:47 AM
  4. Search Form Results Displayed In Report
    By warrenjburns in forum Forms
    Replies: 1
    Last Post: 03-18-2009, 02:08 AM
  5. Replies: 0
    Last Post: 10-16-2008, 02:39 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