+ Reply to Thread
Results 1 to 2 of 2

Adding code to a userform at runtime

  1. #1
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Adding code to a userform at runtime

    The ultimate goal is to create a Userform at run-time.
    The problem is writing event code for that Userform.

    The current situation is:
    I have a userform. (Created with the VBE, not at run-time.) There is one command button on that userform. The code module for that userform is this
    Please Login or Register  to view this content.
    and nothing else.

    I am trying to add a CommandButton1_Click routine to that module. My code for that is in a normal code module.
    Please Login or Register  to view this content.
    When I run showTheForm, the form appears (looking past the form, I can see that the code has been added to the userform's code module), but when I click on the button, nothing happens.
    I dismiss the form, the MsgBox appears, and then the userform (second incarnation) again. And again the command button does nothing.
    Dismissing the userform (via the corner X) ends showTheForm.

    At this point the Private Sub CommandButton1_Click routine is in UserForm1's code module.

    Once again, I run showTheForm, this time starting with the commandbutton routine already in the userform's module.

    This time, the command button works on both incarnations.

    Something about calling a macro, some behind-the-scenes intializing routine is connecting the button and the code.

    How do I make that connection while running my routine? How can I get the CommandButton to run the _Click routine on the first runthrough of showTheForm?

    (Mac OS 9.22, Excel '98)
    also posted to OzGrid
    Last edited by mikerickson; 05-26-2007 at 04:57 PM.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Solved on other site

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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