+ Reply to Thread
Results 1 to 4 of 4

userform cancel button

  1. #1
    davegb
    Guest

    userform cancel button

    I have a cancel button in a userform. The code in the form unloads the
    userform. But I want the cancel button to end the main macro too. I've
    tried numerous conbinations of

    if cbCancel then exit sub

    and a dozen others. None of them work. They either cancel the program
    even if the Cancel button isn't clicked, or don't exit when it is. I
    did a google search here and found a number of routines, none of which
    seemed to apply to my situation (I don't need to check and see if the
    person speaks English to exit. I want my users to be able to exit even
    if they don't speak English!). Can someone give me some simple code to
    put in my macro to close the program if the cbCancel command button has
    been clicked?

    Thanks for the help!


  2. #2
    Norman Jones
    Guest

    Re: userform cancel button

    Hi Dave,

    Try something like:

    In a standard module:

    Option Explicit
    Public blCancelled '<<=== Before any subs

    '=============>>
    Public Sub Tester001()

    blCancelled = False
    UserForm1.Show

    If blCancelled Then Exit Sub
    'Other code, e.g.:
    MsgBox "Hi"

    End Sub
    '<<=============

    In the Userform module:

    '=============>>
    Private Sub cbCancel_Click()
    blCancelled = True
    Unload Me
    End Sub
    '<<=============


    ---
    Regards,
    Norman


    "davegb" <[email protected]> wrote in message
    news:[email protected]...
    >I have a cancel button in a userform. The code in the form unloads the
    > userform. But I want the cancel button to end the main macro too. I've
    > tried numerous conbinations of
    >
    > if cbCancel then exit sub
    >
    > and a dozen others. None of them work. They either cancel the program
    > even if the Cancel button isn't clicked, or don't exit when it is. I
    > did a google search here and found a number of routines, none of which
    > seemed to apply to my situation (I don't need to check and see if the
    > person speaks English to exit. I want my users to be able to exit even
    > if they don't speak English!). Can someone give me some simple code to
    > put in my macro to close the program if the cbCancel command button has
    > been clicked?
    >
    > Thanks for the help!
    >




  3. #3
    davegb
    Guest

    Re: userform cancel button


    davegb wrote:
    > I have a cancel button in a userform. The code in the form unloads the
    > userform. But I want the cancel button to end the main macro too. I've
    > tried numerous conbinations of
    >
    > if cbCancel then exit sub
    >
    > and a dozen others. None of them work. They either cancel the program
    > even if the Cancel button isn't clicked, or don't exit when it is. I
    > did a google search here and found a number of routines, none of which
    > seemed to apply to my situation (I don't need to check and see if the
    > person speaks English to exit. I want my users to be able to exit even
    > if they don't speak English!). Can someone give me some simple code to
    > put in my macro to close the program if the cbCancel command button has
    > been clicked?
    >
    > Thanks for the help!



  4. #4
    davegb
    Guest

    Re: userform cancel button

    Thanks, was exactly what I was looking for.

    davegb wrote:
    > I have a cancel button in a userform. The code in the form unloads the
    > userform. But I want the cancel button to end the main macro too. I've
    > tried numerous conbinations of
    >
    > if cbCancel then exit sub
    >
    > and a dozen others. None of them work. They either cancel the program
    > even if the Cancel button isn't clicked, or don't exit when it is. I
    > did a google search here and found a number of routines, none of which
    > seemed to apply to my situation (I don't need to check and see if the
    > person speaks English to exit. I want my users to be able to exit even
    > if they don't speak English!). Can someone give me some simple code to
    > put in my macro to close the program if the cbCancel command button has
    > been clicked?
    >
    > Thanks for the help!



+ 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