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!
Bookmarks