Results 1 to 4 of 4

vba class module

Threaded View

  1. #1
    Registered User
    Join Date
    09-25-2013
    Location
    Castle Combe
    MS-Off Ver
    Excel 2007
    Posts
    2

    vba class module

    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
    Last edited by Jonty-R; 07-20-2017 at 12:03 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Place code in userform, module or class module
    By nigelog in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2017, 07:04 AM
  2. [SOLVED] ComboBox class .AddItem filled in class module
    By Jacques Grobler in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-03-2012, 05:48 AM
  3. Replies: 1
    Last Post: 08-30-2011, 02:23 AM
  4. [SOLVED] Class Module
    By Bill Martin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-25-2006, 05:00 PM
  5. Module vs Class Module
    By DCSwearingen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-13-2006, 07:45 PM
  6. [SOLVED] Class Module &amp;amp; Module
    By Liedson31 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2005, 11:05 AM
  7. [SOLVED] Class module
    By Avner Mediouni in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-19-2005, 11:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1