Results 1 to 2 of 2

Thread: Combo Box in Search Form
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Aug 2007
    Location
    NJ, USA
    Posts
    76
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Combo Box in Search Form

    Hello

    I have a combo box on my form that gets values from qryTypes and I would like to be able to use these values as a part of my search form. The values display correctly on the form however, I suspect that the code in the VBA below is wrong for cboSearchType.

    All I would like to be able to do is select a value from this drop down and include that as part of the search. So if I select Support in the drop down, I would like for the form to display all records with "Support" as the type.

    Could anyone assist me with fixing my below code?

    Code:
        Dim strWhere As String
        Dim lngLen As Long
        
        If Not IsNull(Me.txtSearchNetworkID) Then
            strWhere = strWhere & "([NetworkID] Like ""*" & Me.txtSearchNetworkID & "*"") AND "
        End If
        If Not IsNull(Me.txtSearchFirstName) Then
            strWhere = strWhere & "([FirstName] Like ""*" & Me.txtSearchFirstName & "*"") AND "
        End If
        If Not IsNull(Me.txtSearchLastName) Then
            strWhere = strWhere & "([LastName] Like ""*" & Me.txtSearchLastName & "*"") AND "
        End If
        If Not IsNull(Me.cboSearchType) Then
            strWhere = strWhere & "([Type] = " & Me.cboSearchType & ") AND "
        End If
    
        lngLen = Len(strWhere) - 5
        If lngLen <= 0 Then
            MsgBox "No criteria", vbInformation, "Nothing to do."
        Else
            strWhere = Left$(strWhere, lngLen)
    
            Me.Filter = strWhere
            Me.FilterOn = True
        End If

  2. #2
    Board Regular
    Join Date
    Jun 2015
    Location
    Ontario, Canada
    Posts
    1,698
    Post Thanks / Like
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Combo Box in Search Form

    This part doesn't look right (in all of them)
    "([NetworkID] Like ""*" & Me.txtSearchNetworkID & "*"") AND "

    I added extra spaces so you can see the difference more clearly.

    "([NetworkID] Like '*' " & Me.txtSearchNetworkID & " '*' ) AND "

    Suggest you use temporary debug.print statments to see what you end up with whenever doing this. If it's sql, you can dump the entire statement into a new query to see if it runs. Problems are usually highlighted by the interpreter when they don't run.
    Last edited by Micron; Jan 13th, 2016 at 07:53 PM.
    Tips for posting problems:
    1) "doesn't work" doesn't help. Post error message text/numbers and/or state what's happening.
    2) if posting code or sql, use code tags; specify on which code line errors occur, if applicable
    3) try to be specific; assume we know nothing about your issue - because we don't!

    Make all suggested changes in copies of your database or to its objects.

    "1 out of 1010 people understand binary. The other 1001 don't."

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •