+ Reply to Thread
Results 1 to 4 of 4

Class Module Events : How to refering to individual class members

  1. #1
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Class Module Events : How to refering to individual class members

    Thank you for reading this

    I want to use the last method of reference inside CBG_Click - how do I do that?
    UserForm1.Buttons(2).CBG.BackColor = vbRed FAILS


    Scenario :Userform with 3 command buttons with group click event (via class module) returning message box "Hello"
    Buttons are added to that group in a particular sequence and I need to use that sequence

    Within the userform code background colour of CommandButton3 can be amended with any of these:
    Me.Controls("CommandButton3").BackColor = vbRed
    Me.CommandButton3.BackColor = vbRed
    Buttons(2).CBG.BackColor = vbRed


    Class Module code (module is named cbClass)

    Please Login or Register  to view this content.
    In Module1
    Please Login or Register  to view this content.
    Userform Code
    HTML Code: 
    Last edited by kev_; 08-29-2020 at 05:44 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  2. #2
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,147

    Re: Class Module Events : How to refering to individual class members

    ....deleted....
    Last edited by Haluk; 08-29-2020 at 05:22 AM.

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,431

    Re: Class Module Events : How to refering to individual class members

    According to your description Buttons was declared in Module1 as a public array of objects cbClass.

    Therefore using the userform1 object to reference it will fail.
    You would need to use

    Please Login or Register  to view this content.

    If you wanted the array within the userform then you could remove the Module1 declaration and use this code in the userform module
    Please Login or Register  to view this content.
    In this example you Double Click the userform to change button colour
    Last edited by Andy Pope; 08-29-2020 at 06:08 AM.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Class Module Events : How to refering to individual class members

    That was simple
    Thank you @Andy Pope

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Using Class Module for handling events of dynamically created controls
    By jagman in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-17-2018, 01:14 PM
  2. Class Module to design a class based on an autoshape (arrow)
    By BluesEnd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-18-2017, 07:23 AM
  3. “= 1st class’ lower class limit + class width"
    By CheeseFace in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2016, 08:21 PM
  4. Class Module & events
    By Desauv86 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-23-2016, 06:24 AM
  5. [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
  6. Replies: 1
    Last Post: 08-30-2011, 02:23 AM

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