+ Reply to Thread
Results 1 to 8 of 8

How to initialize a userform from different places in a sub

  1. #1
    Registered User
    Join Date
    08-21-2019
    Location
    Nancy, France
    MS-Off Ver
    Office 365
    Posts
    3

    How to initialize a userform from different places in a sub

    Good day,

    I have googled and tried various solutions, vainly.

    I am looking for a solution how to initialise a Userform from 2 different subs. The Userform is filled dynamically depending on the content of the sheet List.

    Userform initialise code:
    Please Login or Register  to view this content.
    Sud procedure 1
    Please Login or Register  to view this content.
    the second sub procedure code is somehow
    Please Login or Register  to view this content.
    Following some inputs found on the web, I have done many tests, from which:
    • I have changed the Private to Public without success.
    • I have tried to integrate a Application.Run "'" & UserForm1.Name & "'!UserForm_Initialize"
    • I have tried to define the following in the "main" subs:
    • Dim userForm1 As UserForm1
    • Set userForm1 = New UserForm1
    but I don't manage to get any result.

    I can handle the subs and userform_initialise alone (without linking the userform_initialise to the subs). The Private sub userForm1_initialise () works fine alone, after it is shown, the user will perform a selection of the check boxes and click a button to use this selection and create a new sheet. The selected values are correctly managed afterwards.

    Could someone help and explain how I can manage to initialise the userform from the sub procedures?

    Thanks in advance for any support you could provide me.
    Crissc
    Attached Files Attached Files
    Last edited by crissc; 02-21-2020 at 06:31 PM.

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: How to initialize a userform from different places in a sub

    Within your UserForm code.
    Please Login or Register  to view this content.
    so that it can be called from outside of the UserForm
    Externally from a module
    Please Login or Register  to view this content.
    If you have already loaded the UserForm previously then
    Please Login or Register  to view this content.
    This automatically calls the Initialize event when opening the form

  3. #3
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: How to initialize a userform from different places in a sub

    Just as a general comment, event procedures are designed to run automatically in response to things occurring (e.g. Initialize runs whenever an instance of your class/form is created). They are not really intended to be called from other routines, so if you find yourself needing to do that, you should probably move your code to another routine and call that from the Initialize event and from wherever else you need it.
    Rory

  4. #4
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: How to initialize a userform from different places in a sub

    Although having given the O.P. an answer I fully agree with @rorya (what the O.P. is doing should not be encouraged).
    My response should have been O..M.G. what are you doing - start again - instead of prolonging the agony.
    torachan.

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How to initialize a userform from different places in a sub

    It should be noted that the OP doesn't actually have an initialize event, s/he has a slightly misleading sub named userform1_Initialize in a module...

  6. #6
    Registered User
    Join Date
    08-21-2019
    Location
    Nancy, France
    MS-Off Ver
    Office 365
    Posts
    3

    Re: How to initialize a userform from different places in a sub

    Hello every one and thanks for the support,

    Unfortunately, I can't menage to use the solution shared by torachan.
    I get an error saying: Run-time error: '91' - Object variable or With block variable not set.

    I don't understand this error as I do not have a With block in this part of the code and the code "UserForm1.UserForm_Initialize" does not use a variable.

    Attachment 663711

    In addition: O.P. for outside process? or something else? (sorry for not understanding)

  7. #7
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: How to initialize a userform from different places in a sub

    OP = Original Poster (i.e. you )

    I'm not sure what that attachment is meant to be but the link doesn't work.

  8. #8
    Registered User
    Join Date
    08-21-2019
    Location
    Nancy, France
    MS-Off Ver
    Office 365
    Posts
    3

    Re: How to initialize a userform from different places in a sub

    The attachement is the error popup (second try here) => in Excel 2016 (office 365)

    The error "Compilation error" (in French is in Excel 2013 (using the same code)
    Attached Images Attached Images
    Last edited by crissc; 02-21-2020 at 06:29 PM.

+ 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. How to use the UserForm Initialize event to Initialize 3 listboxes in the same userform
    By Pimp_mentality in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 09-16-2016, 02:59 PM
  2. Userform - help with initialize
    By Macster in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-23-2009, 05:40 AM
  3. Userform initialize
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-14-2008, 09:58 AM
  4. userform initialize
    By Patrick Simonds in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2006, 06:20 PM
  5. userform initialize
    By Patrick Simonds in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-04-2006, 05:40 PM
  6. userform initialize
    By Patrick Simonds in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-04-2006, 05:35 PM
  7. initialize userform, using a sub
    By natanz in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-22-2005, 01:35 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