RawlinsCross
Active Member
- Joined
- Sep 9, 2016
- Messages
- 437
I have labels on both a userform and on a multipage control (6 pages) that I have tied into a class. It's a simple task that when you hover over any of these controls that the backcolor goes vbgreen.
This technique works when the label is one the userform but throws and error "Object doesn't support this property or method" when you hover over the labels on the multipage. Note: I only want this 'vbgreen' behaviour on the multipage controls. I only used the userform labels to check the code - and it works for the userform labels. This leads me to think I have the control reference wrong.
The error is being thrown when I try to access a public procedure back on the userform.
Userform
Class Code
Sorry for the identation, don't know how to paste it with proper formatting.
This technique works when the label is one the userform but throws and error "Object doesn't support this property or method" when you hover over the labels on the multipage. Note: I only want this 'vbgreen' behaviour on the multipage controls. I only used the userform labels to check the code - and it works for the userform labels. This leads me to think I have the control reference wrong.
The error is being thrown when I try to access a public procedure back on the userform.
Userform
VBA Code:
Option Explicit
'userform module varibles
Private AdjustVar() As New AdjustVarClass
Private Sub UserForm_Initialize()
Call PopulateControlsArray
End Sub
Private Sub PopulateControlsArray()
Dim ctrl As Control
Dim lControlCount As Long
For Each ctrl In Me.Controls
If ctrl.Tag = "Adjust" Then
lControlCount = lControlCount + 1
ReDim Preserve AdjustVar(1 To lControlCount)
Set AdjustVar(lControlCount).AdjustVarGroup = ctrl
Set AdjustVar(lControlCount).Parent = Me
End If
Next ctrl
End Sub
Public Sub ResetColor()
Dim ctrl As Control
For Each ctrl In Me.Controls
If ctrl.Tag = "Adjust" Then
ctrl.BackColor = vbWhite
End If
Next ctrl
End Sub
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Call ResetColor
End Sub
Class Code
VBA Code:
Option Explicit
Public WithEvents AdjustVarGroup As MSForms.Label
Private mfrmParent As Object
'--public properties
Public Property Set Parent(frmParent As Object)
Set mfrmParent = frmParent
End Property
'--event procedures
Private Sub AdjustVarGroup_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'This clears resets all the color
Call AdjustVarGroup.Parent.ResetColor '<---- ERROR OCCURS HERE!
'After everything is cleared, this changes the color
AdjustVarGroup.BackColor = vbGreen
End Sub
Sorry for the identation, don't know how to paste it with proper formatting.
Last edited by a moderator: