Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    Quote Originally Posted by Gicu View Post
    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,
    I get Object required if I use that syntax?


    Function is recognised fine regardless?, so no idea what Dave is doing?

    However I got it to work with

    Code:
    Private Sub cmdClearList_Click()
    Call ClearList(Me.lstRepeatNum)
    End Sub
    I belive the first syntax was trying to pass the listbox value and not itself as an object?
    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

  2. #17
    Gina Maylone is offline Always learning
    Windows 10 Access 2016
    Join Date
    Jun 2013
    Location
    Afton, MN
    Posts
    544
    This is what I use:
    Code:
    Private Sub Command95_Click()Dim i As Integer
    For i = 0 To Forms!freportparams!MFGS.ListCount - 1
    Forms!freportparams!MFGS.Selected(i) = False
    Next i
    End Sub

  3. #18
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    Gina,
    I effectively gave that same type code in post #4, and Dave said it did not work for him?

    Vlad is doing the same thing, but more efficiently, as only looking at Selected, not the whole list.?

    MajP over on AWF did it this way as well?, but part of his FAYT listbox class.
    Code:
    Public Sub ClearSelection()
      Dim selectedItem As Variant
      For Each selectedItem In mListbox.ItemsSelected
         mListbox.Selected(selectedItem) = False
      Next selectedItem
    End Sub
    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

  4. #19
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Thank you all for responses, I will come back to this and test all of your versions as there shouldn't be a reason why Function won't recognize when I have other declarations in the same Module such as CannonScan to open printer scanner and various others that work ok!!!!

    Again, appreciate your input

  5. #20
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    Well if the worst comes to the worst, just do it where you would call that function?
    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

  6. #21
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    Good point, can i mix the dim's and code within the same function ?

    I maybe barking up the wrong tree but would that not open the CannonScan when i am clearing list (2 birds with same stone) ?

    Or do you suggest moving further down the public function module ?

  7. #22
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,933
    Quote Originally Posted by DMT Dave View Post
    Good point, can i mix the dim's and code within the same function ?

    I maybe barking up the wrong tree but would that not open the CannonScan when i am clearing list (2 birds with same stone) ?

    Or do you suggest moving further down the public function module ?
    NO!, I mean just clear the list with the simple 3 lines of code wherever you were going to call it as a function?

    So instead of

    Code:
    Blah Blah Blah
    ClearList(Me.lstMainOptions)
    just use
    Code:
    Blah Blah Blah
    Dim varItem
    For Each varItem In Me.lstRepeatNum.ItemsSelected
        Me.lstRepeatNum.Selected(varItem) = False
    Next
    Though I always put my Dims at the top of the module.
    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

  8. #23
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,195
    got you, code as last event on list click, perhaps lost focus so we can confirm there is no clash with procedures

Page 2 of 2 FirstFirst 12
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