Results 1 to 2 of 2
  1. #1
    Exl2Acc is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2016
    Posts
    2

    Using multiple comboboxes to populate one listbox

    Hello...



    The database I working with is a simple employee database and I have several ComboBoxes populated with various components of employees profile. E.g., EmpID's; First Names; Last Names; Supervisors; Shift Start Times; etc.

    What I am trying to achieve is, for example, if the user selects a Shift Start Time from the Shift Start Time ComboBox I would like the ListBox to display all employee records with that Shift Start Time. If the user selects or types an employee's first name in the First Name ComboBox, I would like the ListBox to show all employees with that first name and so on.

    I have this concept working with the Supervisor ComboBox using VBA and a Requery event. But I am unable to get this idea to work across multiple ComboBoxes

    Thanks in advance for guidance.

  2. #2
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    Here is some code to check multiple fields for a search and creates a Where clause based on which fields have data, then populates a listbox with the results. Change the field names to your own. You can see examples of how to do numbers, text and Like conditions of you want it to do some fuzzy searches. Put the function on your form and call it using =QueryData() in the AfterUpdate of each combo box search field.

    Public Function QueryData()

    Dim strWhere, strsqlproject As String

    '** Create a dynamic Where statement from all the search criteria fields that they enter data into on the form.

    If Not IsNull(Me!ProjectID) Then strWhere = strWhere & " AND ProjectID=" & Me!ProjectID
    If Not IsNull(Me!ProjectDescription) Then strWhere = strWhere & " AND ProjectDescription Like '*" & Me!ProjectDescription & "*'"
    If Not IsNull(Me!RiskID) Then strWhere = strWhere & " AND RiskID=" & Me!RiskID
    If Not IsNull(Me!RiskStatusDateLT) Then strWhere = strWhere & " AND RiskStatusDate<=#" & Me!RiskStatusDateLT & "#"

    '** Create SQL statement
    strsqlproject = "Select ProjectID, ProjectName from qryAllData"


    '** Trim leading " AND " from the where clause, then add a GroupBy and OrderBy
    If Not IsNull(strWhere) And strWhere <> "" Then
    strsqlproject = strsqlproject & " WHERE " & Mid$(strWhere, 6)
    End If

    strsqlproject = strsqlproject & " GROUP BY qryAllData.ProjectID, qryAllData.ProjectName"
    strsqlproject = strsqlproject & " ORDER BY qryAllData.ProjectName"

    '** Update the RowSource of the Listbox and requery
    Forms![frmMain]![frmQuery].Form![ProjectList].RowSource = strsqlproject
    Forms![frmMain]![frmQuery].Form![ProjectList].Requery

    End Function

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

Similar Threads

  1. Replies: 3
    Last Post: 03-31-2016, 12:16 PM
  2. Replies: 13
    Last Post: 09-10-2015, 03:37 PM
  3. Replies: 10
    Last Post: 06-18-2013, 02:00 PM
  4. Synchronize multiple comboboxes
    By phyllo in forum Forms
    Replies: 1
    Last Post: 05-01-2012, 01:49 PM
  5. populate textboxes via comboboxes selection
    By white_flag in forum Access
    Replies: 3
    Last Post: 09-08-2011, 01:03 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