Results 1 to 3 of 3
  1. #1
    geotrouvetout67 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    108

    Update List box on Combo Box change

    I have a table (tblReports) containing basically two fields [PurchaseCategory] and [ReportName]. Each report is associated with a purchase category

    In a form I have a List Box (lstReports) that is displaying all the reports available and corresponding purchase categories which display on Form_Load()

    I also have a Combo Box called cboPurchaseCat. When I select the purchase category form that box, I want the List Box to update with showing only the reports for the selected category. Instead it returns blanks and I can't figure out why.

    Here's the code:



    Code:
    Private Sub FilterReportsList()
    
    Dim strReports As String
    
    strReports = "SELECT [ReportName], [PurchaseCategory] FROM tblReports ORDER BY [ReportName]"
    
    If Not IsNull(Me.cboPurchaseCat) Then
        strReports = strReports & " WHERE PurchaseCategory = " & Me.cboPurchaseCat
    End If
    
    Me.lstReports.RowSource = strReports
    
    
    End Sub
    
    Private Sub Form_Load()
    FilterReportsList
    End Sub
    
    Private Sub cboPurchaseCat_Change()
    FilterReportsList
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    WHERE clause goes before ORDER BY.
    Code:
    strReports = "SELECT [ReportName], [PurchaseCategory] FROM tblReports " & IIf(IsNull(Me.cboPurchaseCat), "", " WHERE PurchaseCategory = '" & Me.cboPurchaseCat & "'") & " ORDER BY [ReportName]"
    This assumes PurchaseCategory is a text type field.
    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
    geotrouvetout67 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2019
    Posts
    108
    Thank you so much, indeed that fixed it.

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

Similar Threads

  1. List box update from combo boxes
    By cpullen91 in forum Forms
    Replies: 4
    Last Post: 05-23-2016, 04:31 AM
  2. Change combo box and have it update text box
    By Mattress58 in forum Forms
    Replies: 4
    Last Post: 06-14-2015, 08:02 AM
  3. Replies: 15
    Last Post: 07-22-2014, 07:32 PM
  4. List box update from combo box choice
    By allykid in forum Forms
    Replies: 1
    Last Post: 03-08-2011, 10:06 PM
  5. change textbox value after combo update
    By arctushar@yahoo.com in forum Forms
    Replies: 5
    Last Post: 09-06-2010, 07:17 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