Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 25 of 25

Thread: Call a named Userform Procedure using a variable from a Class

  1. #21
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location



    I am happy to add my 2 bounces - although i have no idea about classes and often fail to make my userform run
    Well done a problem solved is a problem no more



    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  2. #22
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    Attached is the working demo for anyone who may be interested.
    Attached Files Attached Files
    Greg

    Visit my website: http://gregmaxey.com

  3. #23
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Glad you solved it

    Thanks for the upload of the finished product


    Q: So if I want to use it, I'd

    a. Create the UF with controls, etc.

    b. Insert your clsFormControlEvents into the project

    c. Write or customize 3 userform subs and function

    Sub InitializeValidationAndPrompts(),
    Public Sub Change_ValidateControl_Form(oCtrl As Object)
    Private Function fcnValidate(oCtrl As Object) As Boolean

    Thereafter, your 'classy' class does all the heavy lifting
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #24
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    Paul (and SamT too)

    Thank you! Your methods give me something to think about. As for your Q above, yes. That about sums it up. Of course the class at this stage was built to handle the demo. The demo events "Cick" and "Change" "SpinUp/Down" are about the only one I ever use but I can add more (and so can you).

    The prompt piece is builds upon previous work shared with me by Christopher Mackay a few months ago.

    I had come across the CallByName function before when reading through VBA help but the example MS has published doesn't work as written and after fixing it I wandered about the point as the same thing can be done much easier (or seemed to me) without using it.

    SamT's suggestions about setting the form as an object (which I think I had already done in a round about way) stirred a dim recollection of CallByName and the rest is history.

    I've attached a document showing the basic MS example and why I thought it was pointless and showing how the Application.Run falls over and can be overcome.
    Attached Files Attached Files
    Greg

    Visit my website: http://gregmaxey.com

  5. #25
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    I was working on something a couple of months ago where I had to set up two way communication between 2 or more User Defined Objects. I figgered it should work with a UserForm Object.

    Unfortunately, I didn't know about CallByName then.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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