Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2006

    Exclamation Unanswered: Allow User to Input Partial Strings on Textbox to Select Item on Listbox

    I came up with a buggy code to allow a textbox and listbox combination to function in the same way that a combobox would function,

    It gets slow as the listbox no. of items increase or as the search string points to the latter part of the list.

    Private Sub txtSEARCH_Change()
    Dim SearchStr As String
    Dim LstItem As String
    Dim SearchStrLen As Long
    Dim LstBoxCount As Long
    Dim Counter As Long
    SearchStr = txtSEARCH.Text
    SearchStrLen = Len(SearchStr)
    LstBoxCount = lstBOX.ListCount
        For Counter = 0 To LstBoxCount
            lstBOX.ListIndex = Counter
            LstItem = lstBOX.Column(1)
            If Left(LstItem, SearchStrLen) = SearchStr Then
                txtSEARCH.SelStart = SearchStrLen
                Exit Sub
            End If
            If Counter = ToTal - 1 Then
                lstBOX.ListIndex = 0
                Counter = 0
            End If
    End Sub
    i probably should use static type of variable for the counter that determines the listindex, i'm still foggy at this point

    as usual
    any help is greatly appreciated

    Only quitters quit!

  2. #2
    Join Date
    Jun 2005
    Richmond, Virginia USA
    Provided Answers: 19
    I think the first question has to be why you'd want to use a custom textbox/listbox function to replace a native combobox action!
    Hope this helps!

    The problem with making anything that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Apr 2006
    first, I want the user to have a view of some 15 or so records at any time

    second, if he just wanted to look for a particular record, he can just type the first few characters of a key field to locate that record,

    this key field is actually a code so related records are certain to be consecutive.
    once the user locates a particular record, by typing in partial text, he gets to see related records...

    I seem to have made marginal success by using a static variable to hold the listcount whenever the search string exceeded one char, so that the comparison loop doesn't start back at listindex 0, there's still something about losing focus on the textbox...
    Only quitters quit!

Posting Permissions

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