Results 1 to 13 of 13
  1. #1
    jtan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Singapore
    Posts
    29

    Items not auto selected in list box

    Hi guys.



    Appreciate if someone can help.

    in a form, user has to select site and date range. The program will query out and select all the inspectors in that site and date range. But, when change to another site, the program will query out the inspectors, but the selection doesn't work. See attachment. What's wrong?
    Attached Thumbnails Attached Thumbnails items not auto selected in list box.jpg  

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Perhaps you need to run your code in the after update event of the site combo as well.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What event(s) is code in?
    Why do you need to select? What happens with the selection?
    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.

  4. #4
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    430
    you can also add VBA code to the Site combobox AfterUpdate event to select the Inspectors:
    Code:
    Private Sub Combobox1_AfterUpdate()
    Call HiliteList
    End Sub
    
    Private Sub Form_Current()
    Call HiliteList
    End Sub
    
    Private Sub HiliteList()
    Dim X As Integer, Y As Integer
    X = Me.InspectorList.ListCount - 1
    For Y = 0 To X
        Me.InspectorList.Selected(Y) = True
    Next
    End Sub

  5. #5
    jtan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Singapore
    Posts
    29
    Quote Originally Posted by Bob Fitz View Post
    Perhaps you need to run your code in the after update event of the site combo as well.
    Hi Bob,
    I had added the code in site combo box after update event. But, it still doesn't work after changing site.
    See attachment
    Attached Thumbnails Attached Thumbnails items not selected in list box after changing site.jpg  

  6. #6
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Can you post a copy of your db
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Do you mean changing site by selection in combobox or by navigating record?
    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.

  8. #8
    jtan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Singapore
    Posts
    29
    Quote Originally Posted by June7 View Post
    Do you mean changing site by selection in combobox or by navigating record?
    changing site by selection in combo box

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What debugging have you done? Did you set breakpoint and confirm the event actually runs?

    Also suggest you provide db for analysis. Follow instructions at bottom of my post.
    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.

  10. #10
    jtan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Singapore
    Posts
    29
    i'd imported the relevant objects into a new db. See attachmentdb.accdb

  11. #11
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Office 365
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,739
    Replace the entire form code with this.

    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub CustomRequery()
        Dim X As Integer, varItm As Variant
        For Each varItm In InspectorList.ItemsSelected
            InspectorList.Selected(varItm) = False
        Next
           
        Me!InspectorList.Requery
        X = Me.InspectorList.ListCount - Abs(InspectorList.ColumnHeads)
        For X = 0 To X - 1
            Me.InspectorList.Selected(X) = True
        Next
        Me.Refresh
    End Sub
    
    
    Private Sub EndDate_AfterUpdate()
        Call CustomRequery
    End Sub
    
    
    Private Sub Form_Current()
        Call CustomRequery
    End Sub
    
    
    Private Sub Site_AfterUpdate()
        DoEvents
        Call CustomRequery
    End Sub
    
    
    Private Sub StartDate_AfterUpdate()
        Call CustomRequery
    End Sub

  12. #12
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    Methinks that if the list has headers, you need a way to have X loop to start at 1 instead of starting at zero, and increase the count by 1?
    EDIT - to explain further
    Code:
        X = Me.List2.ListCount
        y = Abs(List2.ColumnHeads)
        For X = y To X - 1
            Me.List2.Selected(X) = True
        Next
    because if headers are used, the list count grows by 1. Thus a 4 item listcount is 5 but there are only 4 items to be selected.
    Last edited by Micron; 08-24-2025 at 10:36 AM. Reason: added info
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    jtan is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2013
    Location
    Singapore
    Posts
    29

    Thumbs up

    Quote Originally Posted by davegri View Post
    Replace the entire form code with this.

    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub CustomRequery()
        Dim X As Integer, varItm As Variant
        For Each varItm In InspectorList.ItemsSelected
            InspectorList.Selected(varItm) = False
        Next
           
        Me!InspectorList.Requery
        X = Me.InspectorList.ListCount - Abs(InspectorList.ColumnHeads)
        For X = 0 To X - 1
            Me.InspectorList.Selected(X) = True
        Next
        Me.Refresh
    End Sub
    
    
    Private Sub EndDate_AfterUpdate()
        Call CustomRequery
    End Sub
    
    
    Private Sub Form_Current()
        Call CustomRequery
    End Sub
    
    
    Private Sub Site_AfterUpdate()
        DoEvents
        Call CustomRequery
    End Sub
    
    
    Private Sub StartDate_AfterUpdate()
        Call CustomRequery
    End Sub
    Thank you very much for your code. Problem solved.

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

Similar Threads

  1. How to detect items selected in a list box
    By LonghronJ in forum Modules
    Replies: 3
    Last Post: 08-05-2016, 04:48 PM
  2. Replies: 4
    Last Post: 07-27-2016, 12:07 PM
  3. Replies: 3
    Last Post: 10-23-2012, 03:32 PM
  4. List Box Items Are De-Selected On A Screen Refresh
    By plengeb in forum Programming
    Replies: 2
    Last Post: 10-03-2012, 11:58 AM
  5. Replies: 5
    Last Post: 04-04-2011, 09:57 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