Results 1 to 3 of 3
  1. #1
    dccjr3927 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    130

    Populate Listbox

    I am trying to populate a list box based on selections from two combo boxes.



    Code:
    Private Sub cbxSearchBy_Change()
    Dim strSQL As String
    strSQL = ""
    
    'Creates SQL Query
        Select Case Me.cbxSearchFor.Value
            Case "Work Order"
                Select Case Me.cbxSearchBy.Value
                    Case "Order Number"
                        strSQL = "SELECT OrderNo FROM WOTracking ORDER BY OrderNo;"
                    Case "UPC"
                        strSQL = "SELECT DISTINCT UPC FROM WOTracking ORDER BY UPC;"
                    Case "Employee"
                        strSQL = "SELECT DISTINCT Employee FROM WOTracking ORDER BY Employee;"
                End Select
            Case "Defect Event"
                Select Case Me.cbxSearchBy.Value
                    Case "Customer Name"
                        strSQL = "SELECT CustomerName FROM DefectEvents ORDER BY CustomerName;"
                    Case "UPC"
                        strSQL = "SELECT DISTINCT UPC FROM DefectEvents ORDER BY UPC;"
                    Case "Order Number"
                        strSQL = "SELECT OrderNo FROM DefectEvents ORDER BY OrderNumber;"
                    Case "Status"
                        strSQL = "SELECT DISTINCT Status FROM DefectEvents ORDER BY Status;"
                    Case "Defect Category"
                        strSQL = "SELECT DISTINCT Category FROM DefectEvents ORDER BY Category;"
                End Select
        End Select
    'Populates Listbox
        Me.lstSearchResults.Visible = True
        Me.lstSearchResults.RowSource = strSQL
        Me.lstSearchResults.Requery
        
    End Sub
    Currently, The header in the listbox is filling in with the SQL statement, and not populating. Assisting would be greatly appreciated.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    The listbox RowSourceType property is set to Table/Query?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    dccjr3927 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2019
    Posts
    130
    Thanks June7. I have been working on this project all day. Guess it's time to stop when I miss something like this. By the way, I am still using your:

    Code:
    strSingle = Chr(39)
    strDouble = Chr(34)
    strRepSingle = "^^^^"
    strRepDouble = "~~~~"
    cenSQL = "','"
    endSQL = "');"
    replacement for dealing with single and double quotes in SQL. That was in in 2013. Thanks again for all your help. I'm sure you'll see my user name again soon. Thanks.

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

Similar Threads

  1. listbox doesn't populate
    By ijared in forum Access
    Replies: 9
    Last Post: 05-20-2018, 01:54 PM
  2. Populate ListBox from Table(s)
    By Brightspark98 in forum Forms
    Replies: 2
    Last Post: 02-09-2017, 09:38 AM
  3. Replies: 13
    Last Post: 09-10-2015, 03:37 PM
  4. Populate listbox from Recordset
    By PATRICK in forum Access
    Replies: 8
    Last Post: 10-28-2013, 11:00 PM
  5. Replies: 10
    Last Post: 06-18-2013, 02:00 PM

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