Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Colorado, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing Userform Data to a Caller

    Here's a question from the "stupid" files. I'm working with userforms in VBA (Excel at the moment) and gather data on the form that I need to pass to the calling subroutine. A perfect example is a Cancel button click. As it stands I have to define a public variable to contain a boolean so that I can tell the caller that the cancel button was clicked. Is this really how Micro$oft intended these things to work? This technique seems to violate OOD paradigms. Am I missing a technique whereby I can pass local variables between the callee and the caller (and vice versa)?

    Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Passing Userform Data to a Caller

    You haven't explained what you're actually doing, so there isn't any way to answer your question. Clicking the cancel button should fire an event. But what do you want the cancel button to DO?
    Charlotte

  3. #3
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Colorado, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing Userform Data to a Caller

    In this case, I'm using a userform to get a network drive letter from the user. based on the user's input the calling subroutine imports data using a couple of queries. However, if the user clicks Cancel, I want processing to abort. The only way I've found to do this is to set a global variable to true if cancel is clicked and false otherwise. I realized after I posted the first time that I can get the content of controls that have a value property from the form object as long as it's still loaded, but passing the result of a command button click is the problem.

    HTH

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing Userform Data to a Caller

    Instead of a global var, use the .tag property to store something meaningful about the action the user takes. Of course this is only relevant as long as the form is still loaded -- which you know.

    The technique I use is to set the .tag property of the Cancel button to true if the user clicked it. The next statement in the clicked event is Unload Me (we're talking Word VBA here). The unload calls the query_close event (Workbook_BeforeClose in Excel) which tests for the true in the cancel tag. If so, it's over, the form closes and on you go.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  5. #5
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Colorado, USA
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing Userform Data to a Caller

    That's just the ticket. I've briefly looked at this property before, but never took the time to really learn its true usefulness. My loss ... until now.

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •