RawlinsCross
Active Member
- Joined
- Sep 9, 2016
- Messages
- 437
So I'm trying tie in 7 listboxes to a class for common behaviour. I had this working before, but this is the first time I'm using it with a multipage configuration. Maybe I'm grasping for straws here but it won't recognize the "SelectedListBox" name property? Can anyone ascertain why?
Main Userform Code
Class Module
Main Userform Code
VBA Code:
Private ListBoxControls() As New clsListBoxControl
Private msSelectedListBox As String
'Userform public properties
Public Property Let SelectedListBox(sSelectedListBox As String)
msSelectedListBox = sSelectedListBox
End Property
'Userform methods
Private Sub Userform_Initialize()
Call PopulateControlArrays
End Sub
Private Sub PopulateControlArrays()
Dim ctrl As control
Dim lListBoxCount As Long
For Each ctrl In Me.Controls
If TypeName(ctrl) = "ListBox" Then
lListBoxCount = lListBoxCount + 1
ReDim Preserve ListBoxControls(1 To lListBoxCount)
Set ListBoxControls(lListBoxCount).ListBoxControlGroup = ctrl
Set ListBoxControls(lListBoxCount).Parent = Me
End If
Next ctrl
Stop
End Sub
Public Sub ClearListBoxSelection()
Dim i As Long
For i = 0 To Me.Controls(msSelectedListBox).ListCount - 1
If Me.Controls(msSelectedListBox).Selected(i) = True Then
Me.Controls(msSelectedListBox).Selected(i) = False
End If
Next i
End Sub
Class Module
VBA Code:
Option Explicit
Public WithEvents ListBoxControlGroup As MSForms.ListBox
Private mfrmParent As UserForm
'--public properties
Public Property Set Parent(frmParent As UserForm)
Set mfrmParent = frmParent
End Property
Private Sub ListBoxControlGroup_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal Y As Single)
ListBoxControlGroup.mfrmParent.SelectedListBox = ListBoxControlGroup.Name <---- Fails here, "Object doesn't support this object or method"
If Button = 2 Then
Call ListBoxControlGroup.mfrmParent.ClearListBoxSelection
End If
End Sub