Results 1 to 8 of 8
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    X - Close Dialog (Word XP)

    I've had a user complain that hitting the X in the upper right of a custom dialog causes an error. This error is a negative number with about 18 digits. Oddly, some of our older templates don't raise an error when this X is hit... the dialog simply closes and the code comes to a halt. I can't find anything in the code that traps this error, in fact there is no error trapping in most of these old templates at all.

    I know that I can use the QueryClose event of the form to disable the X. Can anyone offer a clue as to what might be in place to cause the X to simply close the dialog quietly? The document is left half-formed in this case, which isn't desirable in any case.

    Thanks,
    Richard Barrett

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: X - Close Dialog (Word XP)

    Without knowing what the dialog does, and what the exact error message is, it's hard if not impossible to say what's causing this.

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: X - Close Dialog (Word XP)

    Sorry... I chould have attached a shot of the error message. It's attached to this post.

    The dialog is simple... four option buttons, plus OK and Cancel command buttons. This error occurs on nearly every dialog in my templates. There is no server that is called, and the template does not have any references set.

    Am I correct that it is not possible to trap the close icon of form control menu?

    Thanks,
    Richard

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: X - Close Dialog (Word XP)

    The most probable explanation is that your code is trying to refer to the userform after it has been unloaded. Without seeing all of the code it is impossible to be more specific.

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: X - Close Dialog (Word XP)

    Here's a guess: add this to your form's code module and change the contents to whatever is appropriate to your application:

    Private Sub UserForm_Terminate()
    MsgBox "I've been terminated!"
    End Sub

  6. #6
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: X - Close Dialog (Word XP)

    Yes, that is the case. Once I hide the form (event code which fires at OK or Cancel buttons), the code in the module continues. What would be the best way for the code to determine that the userform is has been unloaded? It seems that the X both closes and unloads the user form.

    Thanks,
    Richard

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: X - Close Dialog (Word XP)

    You could do something along these lines in your regular code module:

    Public blnQuit As Boolean
    Sub CallMyForm()
    UserForm1.Show
    If Not blnQuit Then
    MsgBox UserForm1.TextBox1
    Unload UserForm1
    End If
    End Sub


    With this in your form's code module:

    Private Sub CommandButton1_Click()
    Me.Hide
    blnQuit = False
    End Sub

    Private Sub UserForm_Terminate()
    blnQuit = True
    End Sub

  8. #8
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: X - Close Dialog (Word XP)

    Thanks. I actually started to do something along these lines. (UserForm_Terminate also fires after the command button click event that hides the form, so I handled the boolean a bit differently than you suggested.)

    I decided this was too much fussing. Instead, I have an error routine for each dialog. XfrmWhater for frmWhatever, and so on. The error handler sets frmWhatever.Tag = "Cancel" which is what would be the case if the user had hit the Cancel button to exit gracefully. Resume Next follows, which continues the code by executing the cleanup (close document and unload forms) that would normally take place when .Tag = "Cancel".

    I don't put my "action" code behind commandbutton_Click events, as I prefer to have it in the code module for a number of reasons. Our users generally are trained never to use the X (interferes with checking in documents with the DMS), so it's not really an issue most of the time.

Posting Permissions

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