+ Reply to Thread
Results 1 to 4 of 4

Toggle button works on sheet but not when moved to module.

  1. #1
    Registered User
    Join Date
    12-02-2012
    Location
    Silver Bay, MN
    MS-Off Ver
    Excel 2010
    Posts
    47

    Toggle button works on sheet but not when moved to module.

    I placed a toggle button on a userform that toggles between two sheets. Originally, I placed the code with the button as a click event and its worked fine.

    Subequently, I moved the toggle code to a standard module and called it from the forms object. The call works but the toggle code itself produces "Object variable or With block variable not set". Code follows:

    Code In forms object:

    Please Login or Register  to view this content.
    Code in standard module with Option Explicit set:

    Please Login or Register  to view this content.
    I am self-taught and obviously have a lot to learn. Your help will be appreciated.
    Last edited by mandora; 12-27-2012 at 04:39 AM. Reason: Added Code Tags

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Toggle button works on sheet but not when moved to module.

    The reason for the message "Object variable or With block variable not set" is probably because the form reference is missing in statements like:

    Please Login or Register  to view this content.
    You should change those statements to

    Please Login or Register  to view this content.
    where name_of_form needs to be replaced with the actual form name

    Hope this helps.
    If you like my contribution click the star icon!

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

    Re: Toggle button works on sheet but not when moved to module.

    You'd be better off keeping the code where it was. It's generally a bad idea to spread code around your project, it makes it painful when you need to change something in 6 months time when you've forgotten how everything works. It's easy to follow the code if it's logically grouped in the right place - i.e userform code in the userform it relates to

  4. #4
    Registered User
    Join Date
    12-02-2012
    Location
    Silver Bay, MN
    MS-Off Ver
    Excel 2010
    Posts
    47

    Re: Toggle button works on sheet but not when moved to module.

    Thanks for suggestion.

+ 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