+ Reply to Thread
Results 1 to 5 of 5

passing variable from userform

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    passing variable from userform

    I am using the following code to open a userform. Once the userform is open, the user has the option to choose a continue button or a cancel button. If the user is choosing continue, the code is not working (it always skips to the "else" portion of my "if" statement. I can't figure out why it is doing this. Thanks. I have attached a sample of workbook, if needed.
    Please Login or Register  to view this content.
    Userform code:
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by maacmaac; 01-31-2010 at 08:22 PM.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: passing variable from userform

    Hi maacmaac
    all you needed to do was call the sub

    try....


    Please Login or Register  to view this content.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

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

    Re: passing variable from userform

    You could change the userform's code to this. (Note the added function.)
    Please Login or Register  to view this content.
    and change the calling routine to
    Please Login or Register  to view this content.
    The technique is like returning the value of a function in a custom Class.
    Note: In the Function ContinueUpdate, all references after the Me.Show line should be to DisclaimerForm rather than Me, in case the user Cancels or corner X's.
    Attached Files Attached Files
    Last edited by mikerickson; 01-31-2010 at 04:11 AM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: passing variable from userform

    Pike's solution will solve your problem.

    The reason it does not work is due to the scope of your variables.
    The variable Continue declared in the UpdateMasterFile routine is not the same variable used in the button click events.

    http://www.ozgrid.com/VBA/variable-scope-lifetime.htm
    Cheers
    Andy
    www.andypope.info

  5. #5
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,173

    Re: passing variable from userform

    Code is working fine now. Don't quite understand how the "me" commands work (me.show, me.hide, unload me, etc.). Something I need to study. If you have any recommended links and/or books that explains in depth, I would appreciate it. Thanks for all the comments.

+ 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