Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2012
    Posts
    2

    Post Unanswered: Simple Search Form Not So Simple

    Hello everyone. I am currently creating an Access 2007 database to keep track of technology assets for warranty, tagID#, and what location it is at.

    Currently, I have just a single table called "Assets" with all the information. I created a form using just that table and put an unbound combobox in the header with a search button. This is to just search through the location of the fields currently in the table.

    My code for the search button is:

    Code:
    Private Sub Command32_Click()
    Me.Filter = "Location= " & Chr(34) & coboLocation.Column(1) & Chr(34) 
    Me.FilterOn = True
    End Sub
    I click the button and absolutely nothing happens at all. All three test records are still present, nothing changes. I am completely unsure what is going on here.
    Last edited by seuta; 01-04-12 at 18:23. Reason: Clarification and ytops.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Change your code to:
    Code:
    Private Sub Command32_Click()
    
        Debug.Print "Location= " & Chr(34) & coboLocation.Column(1) & Chr(34) 
        Stop
        Me.Filter = "Location= " & Chr(34) & coboLocation.Column(1) & Chr(34) 
        Me.FilterOn = True
    
    End Sub
    Then open the Debug window (Ctrl+G), re-open the form, perform a search and see what you get for a filter: it will be displayed in the Debug (immediate) window when the code stops.

    The explanation could be that the first (leftmost) column of a combobox is Column(0).

    Note: With this technique, you do not perform a search on the row set, you actually filter it (i.e. the rows that do not match the criteria are excluded from the form records).
    Have a nice day!

  3. #3
    Join Date
    Jan 2012
    Posts
    2
    Quote Originally Posted by Sinndho View Post
    Change your code to:
    Code:
    Private Sub Command32_Click()
    
        Debug.Print "Location= " & Chr(34) & coboLocation.Column(1) & Chr(34) 
        Stop
        Me.Filter = "Location= " & Chr(34) & coboLocation.Column(1) & Chr(34) 
        Me.FilterOn = True
    
    End Sub
    Then open the Debug window (Ctrl+G), re-open the form, perform a search and see what you get for a filter: it will be displayed in the Debug (immediate) window when the code stops.

    The explanation could be that the first (leftmost) column of a combobox is Column(0).

    Note: With this technique, you do not perform a search on the row set, you actually filter it (i.e. the rows that do not match the criteria are excluded from the form records).
    Thank you very much, Sinndho. The values being in a different column was part of the problem. Your help was very useful and greatly appreciated, thank you!

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

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
  •