Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368

    Deselecting list causing issue

    Hi Guy's



    I am trying use a de select option in a list, so this line:

    Me.lstMainOptions.ListIndex = -1

    I have the above line as very last in the on click procedure so it allows the option to execute (does that fine)

    I have a tab control on my MainMenu, after I have selected anything in the list, then the tab pages on my main form doesn't respond to selecting pages !!

    once i remove Me.lstMainOptions.ListIndex = -1 then all works normal ??

    My aim was to once list item selected then remove the highlighted selection from the list

    DO you think the option i am using is the best option to deselect list items (last line in procedure)

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    Not enough to go on here.
    A list box has no natural interaction with a tab page so you must have some code that is doing something after the listbox selection.

    Post up the whole code or better still a bit of database that demonstrates what's happening, or not.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    Hi Minty, thank you, i thought it shouldn't effect as there is no interaction

    I will do some more work and come back if i can't find a solution, you have confirmed what i thought that there is no link the end of a procedure and selecting another option mot related

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,568
    Here is how I deselected listbox entries until I used MajP listbox class. Now commented out.

    Code:
    'Dim i As Integer
    '
    'For i = Me.lstCrew.ListCount - 1 To 0 Step -1
    '    Me.lstCrew.Selected(i) = False
    'Next
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Is the listbox set to multiselect? You could reset its row source or use the following function:
    Code:
    Function ClearList(lst As ListBox) As Boolean
    Dim varItem
    If lst.MultiSelect = 0 Then
    	lst = Null
    Else
    	For Each varItem In lst.ItemsSelected
    		lst.Selected(varItem) = False
    	Next
    End If
    End Function
    To use it in your click event:
    Code:
    ClearList(Me.lstMainOptions)
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    Hi Guys, no not set to multi select, I will test your suggested solutions

    Thanks guys, will confirm back

  7. #7
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    Tried a version of WGM, list doesn't deselect

    my version of WGM

    Code:
    Dim iItems As Integer
    
    For iItems = Me.lstMainOptions.ListCount - 1 To 0 Step -1
        Me.lstMainOptions.Selected(iItems) = False
    Next
    Bizarre when i have tried Vlad's sub or function not defined

    so changed to Public Function

    Function not defined

    Code:
    Option Compare DatabaseOption Explicit
    Public Function ClearList(lst As ListBox) As Boolean
    Dim varItem
    If lst.MultiSelect = 0 Then
        lst = Null
    Else
        For Each varItem In lst.ItemsSelected
            lst.Selected(varItem) = False
        Next
    End If
    End Function
    Then run the function as suggested!!!!

    It's not mega important but would be good not to have the list highlighted after procedures of list events

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,568
    Vlad's would be better as that just looks at those selected, so in your case, just the one. Mine went through the whole list, not knowing any better.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Can you please show both the public function and how you call it (the click procedure)? No need to make the function return a boolean, just leave it as I post it.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  10. #10
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    Hi Vlad, so i have added the following to my module called Public Functions

    Code:
    Option Compare DatabaseOption Explicit
    Public Function ClearList(lst As ListBox) As Boolean
    Dim varItem
    If lst.MultiSelect = 0 Then
        lst = Null
    Else
        For Each varItem In lst.ItemsSelected
            lst.Selected(varItem) = False
        Next
    End If
    End Function
    I have added the following to the last procedure my list on Click event

    The full event is quite large but basically the list is set a table/Query from tblMainList with 2 fields

    field 1 is RecordNo set to Number field 2 is ListItems

    lstMainList column(0) (record No) is set to zero width and column(1) is set to display (ListData)

    Then using select case Me.lstMainList.Column(0)

    Case 1
    Open Form
    Case 2
    Send Email
    etc etc..

    unsure if it makes a difference that the list source is table.query and not value list ?

    anyhow this is the last part of code as full procedure is large

    Code:
    Case 5    
            DoCmd.OpenForm "frmStorage"
        
        Case 6
        
        
            DoCmd.OpenForm "frmSearch"
        
        If Not IsNull(Forms!frmMainMenu!frmIndex1!cboCustomer) Then
            strCust = Forms!frmMainMenu!frmIndex1!cboCustomer
        Else
            strCust = DLookup("Name", "tblCustomers", "[RecordNo] = 98")
        End If
        
        Forms!frmSearch!txtCustomer = strCust
        
    
    
    End Select
    
    
    ClearList (Me.lstMainOptions)
    
    
    
    
    
    
    End Sub

  11. #11
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Can you try this please:
    Code:
    Public Function ClearList(lst As ListBox) 
    Dim varItem
        For Each varItem In lst.ItemsSelected
            lst.Selected(varItem) = False
        Next
    End Function
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  12. #12
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    Hi Vlad, i have ticked require variable declarations in alt F11/Tools/Options

    I have this issue before i think when trying to run from Function!!

    Code:
    Option Compare DatabaseOption Explicit
    Public Function ClearList(lst As ListBox)
    Dim varItem
        For Each varItem In lst.ItemsSelected
            lst.Selected(varItem) = False
        Next
    End Function
    Click image for larger version. 

Name:	Capture.JPG 
Views:	9 
Size:	21.4 KB 
ID:	49278

  13. #13
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    This topic is not super important but i know it should work from suggestions

    It is one of those where if you have started something, don't be beat in completing it

  14. #14
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    A Plan B i am thinking is to set the focus elsewhere it's just a matter of which event

    currently using on click for the list

    maybe on exit/after update/on lost focus

  15. #15
    DMT Dave is online now VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,368
    Hi Again Vlad, I have found this does the trick but still unsure why function won't recognize!!!!!

    Code:
    Private Sub lstMainOptions_LostFocus()
    Me.lstMainOptions.ListIndex = -1
    Me.lstMainOptions.Requery
    End Sub

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. List Box issue
    By Savannah in forum Access
    Replies: 4
    Last Post: 03-17-2017, 10:06 PM
  2. Replies: 2
    Last Post: 07-14-2014, 10:34 AM
  3. List Box Issue
    By Igawa29 in forum Programming
    Replies: 4
    Last Post: 02-22-2011, 01:19 PM
  4. Dsum causing speed issue
    By ethoemmes in forum Queries
    Replies: 0
    Last Post: 07-06-2010, 05:22 AM
  5. Replies: 1
    Last Post: 07-30-2009, 12:54 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