Unselect UserForm Listbox Selection in Double Click (1 Viewer)

meilkew

New member
Local time
Today, 22:03
Joined
Apr 14, 2020
Messages
27
I have this code which open the PDF files if the filepath is available in the listbox index and msg box if "NO PDF FILE" text is found instead. I would like to clear the selection made as soon as the PDF or MsgBox fires. But somehow declaring this at the end of the code doesn't do the work.
Me.ListBoxSD.Selected(i) = False

What happen is if I made a new selection in the list box whether above or below of the previous selection, several rows are being highlighted instead.

My list box is set to multi select extended. I tried calling the Me.List_box_Data to update the record in hope to clear the selection made.

Code:
Private Sub ListBoxSD_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

TurnOffFunctionality
Dim strFile As String
Dim i As Long

i = Me.ListBoxSD.ListIndex
Me.ListBoxSD.Selected(i) = True

strFile = Me.ListBoxSD.List(Me.ListBoxSD.ListIndex, 17)

    If Me.ListBoxSD.Selected(i) Then
   
        If strFile = "NO PDF FILE" Then
       
           MsgBox "No Attachment"
               
        Else
     
       ActiveWorkbook.FollowHyperlink strFile
   
   End If
 
End If

Me.ListBoxSD.Selected(i) = False

Call Me.List_box_Data
TurnOnFunctionality

End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:03
Joined
Sep 21, 2011
Messages
14,273
This is how I dedelected my listbox entries.?

Might not be the best way, but it does work?

Code:
Private Sub cmdClear_Click()
Dim i As Integer

For i = Me.lstCrew.ListCount - 1 To 0 Step -1
    Me.lstCrew.Selected(i) = False
Next

HTH
 

Users who are viewing this thread

Top Bottom