Results 1 to 10 of 30

Thread: Class related Stuff Userforms

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #9
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10

    https://www.excelforum.com/excel-pro...ml#post4382802
    https://www.excelforum.com/excel-pro...ml#post4382894
    https://www.excelfox.com/forum/showt...ll=1#post24175






    Thanks Rory,

    Just one last thing to make sure I got it..
    Originally Posted by rorya
    ... That's why the changes weren't being reflected in your code - you were referring to two separate instances of the form......


    I was referring originally ( in my Debug check lines ) to
    ufResults..

    That was not an instance was it, as it is the original ( Blueprint ).... Or is it... In this case....

    Alan

    _.___________
    Rory (Romperstomper) 05-10-2016, 10 May 2016

    Yes it is. As soon as you use ufResults for the first time, a new instance of the form is created. It's confusing because you effectively get a variable of the same name as the class. So that instance was not the same as the fm instance. (If you'd added a Debug.Print Userforms.Count line in there, you'd have seen 2 forms)

    For a simple demo, in a new workbook, add a blank userform, then add this code and run it:
    Code:
    Sub foobar()
        Dim fm As UserForm1
        Set fm = New UserForm1 ' created an instance of the form
        MsgBox UserForms.Count ' you'll see 1 here
        UserForm1.Caption = "Loaded another instance" ' this loaded a new instance of the form and assigned a variable called Userform1
        MsgBox UserForms.Count ' so you'll see 2 here
    End Sub
    Last edited by DocAElstein; 06-01-2024 at 06:42 PM.

Similar Threads

  1. Class Stuff: VBA Custom Classes & Objects, Class Modules
    By DocAElstein in forum Excel and VBA Tips and Tricks
    Replies: 29
    Last Post: 06-02-2024, 01:49 PM
  2. Replies: 42
    Last Post: 05-29-2023, 01:19 PM
  3. Test my rights , to do stuff
    By TestAccount in forum Test Area
    Replies: 0
    Last Post: 10-07-2020, 11:49 AM
  4. Backup all modules, class modules and userforms to a selectable folder
    By MrBlackd in forum Excel and VBA Tips and Tricks
    Replies: 1
    Last Post: 04-06-2014, 08:33 AM
  5. Pass Values Between Multiple Userforms
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 07-24-2011, 03:25 AM

Posting Permissions

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