Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Sep 2006
    Location
    Quilmes, Argentina
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Updating Listbox on keypress (A2K)

    Hi all,
    I have a listbox whose rowsource I set up to be:
    <code>strSQL = "SELECT * FROM myTABLE WHERE myFIELD LIKE '"& TextBox.Value &"*' "</code>
    and I want to update my listbox (ie, run the above query) everytime I type a character on the Textbox.
    So that if the key I pressed was "a" the rowsorce of the lisbox should be:
    <code>SELECT * FROM myTABLE WHERE myFIELD LIKE 'a'</code>
    and if I then press key "b" the rowsorce of the listbox will be:
    <code>SELECT * FROM myTABLE WHERE myFIELD LIKE 'ab'</code>

    I've tried with the onKeypress event but I failed!

    Some advice? Thanks
    Queque

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Updating Listbox on keypress (A2K)

    Welcome to Woody's Lounge!

    Try the On Change event of the text box:

    Private Sub TextBox_Change()
    Me,ListBoxName.Requery
    End Sub

  3. #3
    New Lounger
    Join Date
    Sep 2006
    Location
    Quilmes, Argentina
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating Listbox on keypress (A2K)

    Hans,
    Thanks for the Welcome and for your almost immediate answer!
    But I regret to say that it didn't work!
    I added the line "Call my Function" to your lines because I need to change my SQL query too!

    <code>Private Sub TextBox_Change()
    Call myFunction
    Me.ListBox.Requery
    End Sub</code>


    I want it to work like any CHM file's Index that constantly updates the results list as you type, excluding those entries that not match what you are typing.

    Thank you again!

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Updating Listbox on keypress (A2K)

    Try using TextBox.Text in the SQL code for the Row Source. The Text property contains the currently entered text, while the Value property contains the 'stored' value.

  5. #5
    New Lounger
    Join Date
    Sep 2006
    Location
    Quilmes, Argentina
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating Listbox on keypress (A2K)

    Thanks Hans!! It works properly!
    You always find the solution!!!!

    Although I'm a new member I've been reading different posts in this website lately
    and you have already helped me.

    Thank you Again!!

Posting Permissions

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