Results 1 to 5 of 5
  1. #1
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94

    Searching in comboboxes: functionality and workarounds


    This thread could easily go on the forms section but since depending on the answer it would imply code, I'll open it here.

    I know that when you allow typing on a combobox, access looks for any record on it matching the typed text, but it does so only on the first visible column (field) of the combobox. Is it possible for access to perform the search on all visible columns of the combobox?

    And assuming the answer to the previous question is no, is it too inefficient to fire up a query when text changes in the combobox to filter it with the entered string? That would be an easy workaround but I feel that executing a query every time a character is entered or deleted is a bad idea.

    Thank you all!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    No. Combo Items needed should only be in 1 column.

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you can use VBA code to modify the rowsource to apply criteria.

    Plenty of more complete examples about but in principle for a combo called say cboCustomers with a rowsource of say:

    Code:
    SELECT ID, custName, custAddress FROM tblCustomers ORDER BY custName
    in the combo enter event (required to 'reset' the list)

    Code:
    me.cboCustomers.rowsource="SELECT ID, custName, custAddress FROM tblCustomers ORDER BY custName"

    in the change event this air code. You may need additional code for error checking, returning the cursor to the correct position etc

    Code:
    if cboCustomers.Text<>"" Then
         me.cboCustomers.rowsource="SELECT ID, custName, custAddress FROM tblCustomers WHERE custName Like '*" & cboCustomers.Text & "*' OR custAddress Like '*" & cboCustomers.Text & "*' ORDER BY custName"
    else
       cboCustomers_enter()
    end if
    but I feel that executing a query every time a character is entered or deleted is a bad idea.
    That is the only way to do it simply. You would need to try it and see whether it has a significant effect on performance. Note that using the initial * prevents the use of indexing so do not use unless you have to

    Other things to do is to not run the code until at least say 3 characters have been entered, or use the form timer event to execute the code say 1/2 second after the use stops typing

  4. #4
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94
    Quote Originally Posted by ranman256 View Post
    No. Combo Items needed should only be in 1 column.
    I have a combobox to add users to a workstation, and I want the DB operator to search for the user by the username or by the person's name (which are completely different) thus the multiple columns. Ideally, typing in the combobox would search/filter by both fields.

    Quote Originally Posted by Ajax View Post
    you can use VBA code to modify the rowsource to apply criteria.
    That was my plan as a workaround but I fear it'll hurt the performance. I'll try it as soon as I have a moment to implement and test it. Thanks, Ajax.

  5. #5
    sxschech is offline Novice
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    5
    You might also look into FAYT find as you type. I use this and it allows to search anywhere within the cols of a combobox. Once you start typing letters, it narrows down the list.

    Post #7 has the download that I use. (there is another version in Post #17) There are additional discussions and attachments, but if your situation is straightforward, then post #7 attachment should provide what you need.

    https://www.access-programmers.co.uk...-typed.315813/

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

Similar Threads

  1. Database Functionality
    By joshrastatter in forum Database Design
    Replies: 1
    Last Post: 05-13-2016, 06:43 AM
  2. Replies: 3
    Last Post: 03-31-2016, 12:16 PM
  3. Tab Index Functionality in 2007
    By Paul H in forum Forms
    Replies: 8
    Last Post: 08-18-2015, 02:17 PM
  4. How to add functionality to project
    By fluppe in forum Programming
    Replies: 8
    Last Post: 07-29-2014, 08:26 PM
  5. Semi-colon Functionality
    By TheDeceived in forum Access
    Replies: 3
    Last Post: 09-22-2010, 10:52 AM

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