Results 1 to 2 of 2
  1. #1
    joesmithjunior is offline Novice
    Windows 7 32bit Access 2010 64bit
    Join Date
    Nov 2011
    Posts
    4

    Filtering records with a combo box

    Can anyone please tell me how I can modify this code to make it filter results in a combo box by what the user types in to search for. Thanks



    Private Sub txtSearch_AfterUpdate()
    With Me.RecordsetClone
    .FindFirst "[FirstName]=""" & Me.txtSearch & """ OR [Lastname]=""" & Me.txtSearch & """"
    If .NoMatch Then
    Beep
    Else
    Me.Bookmark = .Bookmark
    End If
    End With
    End Sub

    Private Sub Combo1254_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[ID] = " & Str(Nz(Me![Combo1254], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    End Sub

    Private Sub Combo1256_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[CUST] = '" & Me![Combo1256] & "'"
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    You want to allow users to enter their spelling for a name and search for it? If you must allow pattern matching, need to use LIKE operator. I have never tried this with the FindFirst method:
    .FindFirst "[FirstName] LIKE " & Me.txtSearch & "* OR [Lastname] LIKE " & Me.txtSearch & "*"

    Why not limit user to selecting names from a combobox row source?

    You appear to be doing that with the Combo1254 event although don't know why you are using Str conversion. Is CUST a text field for customer unique ID? Why use recordset in the combobox events? The RecordsetClone property as shown in the first procedure should work as well.

    This article might be of interest http://allenbrowne.com/ser-32.html
    Last edited by June7; 12-20-2011 at 07:04 PM.
    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.

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

Similar Threads

  1. Error with filtering subform using 2 combo boxes
    By dharmacloud in forum Forms
    Replies: 4
    Last Post: 08-22-2011, 10:46 AM
  2. list form filtering from 1 combo box
    By cooper in forum Forms
    Replies: 5
    Last Post: 08-18-2011, 05:32 PM
  3. Filtering options using Cascading Combo boxes
    By Lincoln in forum Database Design
    Replies: 3
    Last Post: 07-15-2011, 08:25 PM
  4. Combo Box Filtering between Forms
    By andrew_ww in forum Access
    Replies: 3
    Last Post: 12-30-2009, 11:06 PM
  5. Replies: 0
    Last Post: 08-17-2008, 12:19 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