+ Reply to Thread
Results 1 to 13 of 13

Form Button_Exit is not executing at right time

  1. #1
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Form Button_Exit is not executing at right time

    In my userform I click a button "Load" inside a frame.
    Focus is on the "Load" button.
    I then click the "Cancel" button. The Cancel_Enter() & Cancel_Click() execute BEFORE the Load_Exit().

    The same thing happens if I click a CheckBox inside the same frame. The focus is on the checkbox.
    When I click the "Cancel" button the Cancel_Enter() and Cancel_Click() execute BEFORE the Checkbox_Exit()

    Is it supposed to do things in that order? How do I get the Load_Exit() or CheckBox_Exit() to execute before the Cancel_Click()?
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Form Button_Exit is not executing at right time

    What tasks have you put in Load_Exit() and CheckBox_Exit ?



  3. #3
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Form Button_Exit is not executing at right time

    Is the Cancel button inside the same frame?
    Remember what the dormouse said
    Feed your head

  4. #4
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Form Button_Exit is not executing at right time

    No, the Cancel button is not inside a frame. It is grouped with the OK button.

  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Form Button_Exit is not executing at right time

    Then I think you are stuck unless you move the Load button out of its frame.

  6. #6
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Form Button_Exit is not executing at right time

    snb;

    In the Exit() I put a call to a sub that checks to see if any controls have changed values, and if so changes the "Ok" button caption to "Save" and enables or disables a "Reset" button.

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Form Button_Exit is not executing at right time

    I suspected that kind of thing.
    I prefer the checking of changed values in the Change event of each control that can be changed. You can use a common macro tot do those checks: e.g.

    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Form Button_Exit is not executing at right time

    snb;

    Your suggestion sounds good at first, but I want to explore it a little further.

    I do have a common sub that is called from every control's exit() event. The sub compares the current value of every control with it's original value (which was set during initialize).

    Every time I create a TextBox_Change() event, it executes with every letter entered into the TextBox. Is there a way to have it wait until the user has finished entering the change? The Exit() event does that.

    Or is there a way to pass the TextBox to a sub and have it compare the current value to the original value, without having to continually be searching through a list of original values looking for the one that matches the control passed, which might take too long between letters.
    I think I just figured out my own answer. I can have the form create controls during the initialize event with names that are made from the names of the controls on the form and store the original values in those controls. Then it's easy to compare the control with the created control with the similar name.
    Last edited by foxguy; 09-17-2010 at 02:45 AM.

  9. #9
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Form Button_Exit is not executing at right time

    Store the values in the control's tag property at startup.

  10. #10
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Form Button_Exit is not executing at right time

    Instead of using

    Please Login or Register  to view this content.
    you could use the BeforeUpdate event:

    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Form Button_Exit is not executing at right time

    romperstomper;

    You always come up with things I haven't thought of. Which is really strange this time since I use the tag property for something else on one of the controls.

  12. #12
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Form Button_Exit is not executing at right time

    snb;

    What's the advantage of using the BeforeUpdate() instead of the Exit()?

  13. #13
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Form Button_Exit is not executing at right time

    You yourself noticed a certainorder in which events happen.
    You can check/test whether the beforeupdate event is being triggered at the 'right' time (as you put it). Since we can't read your userform we can't test it.
    If the tag property is already in use you can easily add a hidden combobox with all the names you want to use in the test. But you can also use the tagproperty of another control, e.g. Frame1.Tag=textbox1.text &"|" & textbox2.Text & "|" & textbox3.Text etc.
    Last edited by snb; 09-17-2010 at 04:40 AM.

+ 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