OK...I'm stuck!
Ive never really had to use class modules before, so still getting to grips with them. I am trying to build the class module to manage the controls on a form. I have a set of text boxes working so I'm hoping I am grasping the concepts, however the problem I have is that frame doesn't generically have either Enter or Exit events when used within a class. These I require and so I have elected to build them.
So I have had to build a class module with added events and then trigger the events using a RaiseEvent command. This I can make work when only 1 instance of the class, however since vba doesn't allow you to dimensionalise an array as a class object I have had to use a collection. The standard events that are contained within the class work perfectly well...however the RaiseEvent doesn't. I can but assume that the events in the main form relate to a different instance so aren't being triggered.
Does anyone out there know a way around this?
Class Module
Option Explicit
Public WithEvents NewFrame As MSForms.Frame
Public Event EnterFrame()
Public Event ExitFrame(ByVal Cancel As MSForms.ReturnBoolean)
Private m_oFrm As Object
Public Property Set MainFrm(oFrm As Object)
m_oFrm = oFrm
End Property
Public Property Let Visibility(bVis As Boolean)
Dim Cancel As Variant
Cancel = False
With NewFrame
If .Visible <> bVis Then
.Visible = bVis
If bVis Then
RaiseEvent EnterFrame
Else
RaiseEvent ExitFrame(Cancel)
End If
End If
End With
End Property
Form Module
Option Explicit
Private WithEvents fraHnd As cFrameHandler
Public m_oFrames As Collection
Private m_lTop As Long
Private Sub fraHnd_EnterFrame()
Debug.Print ": Click"
End Sub
Private Sub fraHnd_ExitFrame(ByVal Cancel As MSForms.ReturnBoolean)
Debug.Print ": Exit"
End Sub
Private Sub tabMenu_Change()
DisplayFrame
End Sub
Private Sub UserForm_Initialize()
Set m_oFrames = New Collection
Set fraHnd = New cFrameHandler
AddFrame fraTest1, eTabTest1
AddFrame fraTest2, eTabTest2
AddFrame fraTest3, eTabTest3
AddFrame fraTest4, eTabTest4
tabMenu.Value = eTabTest1
End Sub
Private Sub AddFrame(oFra As MSForms.Frame, lTab As gm_eTestTabs) 'sCaption As String, lColour As Long)
Dim oHnd As cFrameHandler
With oFra
.Left = 6
.Top = 18
.Height = 250
.Width = 200
.Tag = lTab
End With
Set oHnd = New cFrameHandler
Set oHnd.NewFrame = oFra
Set oHnd.MainFrm = Me
m_oFrames.Add oHnd
End Sub
Private Sub DisplayFrame()
Dim oFra As cFrameHandler
Dim oFraSelect As cFrameHandler
For Each oFra In m_oFrames
If (oFra.NewFrame.Tag = tabMenu.Value) Then Set oFraSelect = oFra
oFra.Visibility = False
Next oFra
oFraSelect.Visibility = True
' oFraSelect.NewFrame.SetFocus
End Sub
Bookmarks