Results 1 to 9 of 9

Run-Time Error 91 When Dynamically Creating Controls and Event Handlers

Threaded View

chucklod Run-Time Error 91 When... 01-10-2008, 01:58 PM
Leith Ross Hello chucklod, I made the... 01-10-2008, 05:20 PM
chucklod Almost there 01-11-2008, 04:12 PM
Leith Ross Hello Chuck, The response... 01-11-2008, 06:46 PM
chucklod Many thanks 01-16-2008, 11:53 AM
  1. #1
    Registered User
    Join Date
    01-07-2008
    Posts
    38

    Run-Time Error 91 When Dynamically Creating Controls and Event Handlers

    I'm trying to create a userform and controls at run-time, then add controls in response to user actions. The controls would need event handlers.

    For example, the form would have a button (AddEventProcButton) whose event handler (AddEventProcButton_Click) would create another button (TestEventProcButton) and an event handler (TestEventProcButton_Click) for that button.

    I have successfully created the form and the first button and its event handler, which calls another subroutine (AddTestButton, that then adds the second button and its event handler). But when I click the first button, I get the following error message:
    Run-time error '91':
    Object variable or With block variable not set
    The interesting thing is I can invoke the AddTestButton subroutine from the initial macro and it works just fine, but invoking it from the event handler (AddEventProcButton_Click) gives the error message. The initial macro and subroutine are in a separate module (Module1) and the event handlers are created in the code module of the new userform.

    If that isn't clear enough, I've attached the spreadsheet. You can invoke the macro named DoDataPoints and then click the button on the userform that displays, which will cause the error.

    Thanks for any help you can give!
    Attached Files Attached Files

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