Solved

Form vb for Unbound Listbox filtering based on Unbound Textbox

Posted on 2014-01-01
2
908 Views
Last Modified: 2014-01-01
Happy New Year to All!

Trying to filter an unbound listbox of last names based upon the users input in an unbound textbox as they input each character in that textbox.  However I'm missing something.

The RecLName field is set as Text

Private Sub txtLName_Change()
Dim strLName As String, lngLenLName As Long, lngSortSel As Long
lngSortSel = Me.frameExistingParties.Value

    If IsNull(Me.txtLname.Text) = False Then
        strLName = Me.txtLname.Text
        lngLenLName = Len(Me.txtLname.Text)
        If lngSortSel = 1 Then
            Me.lstExistingParties.RowSource = "SELECT RecPartyID, RecLName, RecFName, RecMName, RecSufName, RecEntityName, EntityNameType, PartyFullNameFML, PartyFullNameLFM, SortName FROM qrytbl_Parties WHERE RecLName LIKE " & "'" & strLName & "' ORDER BY SortName ASC "
        Else
            Me.lstExistingParties.RowSource = "SELECT RecPartyID, RecLName, RecFName, RecMName, RecSufName, RecEntityName, EntityNameType, PartyFullNameFML, PartyFullNameLFM, SortName FROM qrytbl_Parties WHERE RecLName LIKE " & "'" & strLName & "' ORDER BY SortName ASC "
        End If
    Else
    End If

End Sub

Open in new window


My listbox simply goes blank after I input the first character in that textbox
0
Comment
Question by:wlwebb
2 Comments
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 39749640
You're using LIKE with a finite value - in other words, if I typed an 'a', your code is asking for all records where RecLName is LIKE 'a'. Unless you have a record where the value in RecLName is 'a' (and ONLY 'a') then you wouldn't find anything.

You need to use the wildcard operator with LIKE:

 Me.lstExistingParties.RowSource = "SELECT RecPartyID, RecLName, RecFName, RecMName, RecSufName, RecEntityName, EntityNameType, PartyFullNameFML, PartyFullNameLFM, SortName FROM qrytbl_Parties WHERE RecLName LIKE '"  strLName & "*' ORDER BY SortName ASC "

Open in new window


Note the asterisk ( * ) AFTER the strLName variable. So if I typed 'art' it would find arthur, atrid, etc.  It would not find McArthur, however. to do that, you could also use:

 Me.lstExistingParties.RowSource = "SELECT RecPartyID, RecLName, RecFName, RecMName, RecSufName, RecEntityName, EntityNameType, PartyFullNameFML, PartyFullNameLFM, SortName FROM qrytbl_Parties WHERE RecLName LIKE '*"  strLName & "*' ORDER BY SortName ASC "

Open in new window


Note there are preceding and trailing asterisks. This would find any instance of the value typed. For example, if I typed 'art' it would find arthur, artid, etc,
0
 

Author Closing Comment

by:wlwebb
ID: 39749642
Thank you Scott!  Missed that one.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question