Consulting

Results 1 to 3 of 3

Thread: Solved: QueryUnload is firing in an unused Form

  1. #1
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location

    Solved: QueryUnload is firing in an unused Form

    I have a VB 6 ActiveX DLL that contains 12 Forms.

    The DLL is used by Word.

    A toolbar/menu starts macros that invoke the 6 main Forms.

    Each Form has a QueryUnload event similar to the one given below.
    Only 1 of the Forms has the specific Msgbox listed below. The others have
    quite different text.

    However, yesterday, something very odd started happening.
    I would start a macro, and use the appropriate buttons to close the Form.
    No problem doing this.

    However, when I then exit from Word, somehow, this causes the code below to
    be invoked a Form that was not even used during the current Word session.
    The message below is issued, even tho the Form was not used and the Close
    box was not used with any Form.
    After I respond to the Msgbox, less than a minute later, I get a nasty
    screen stating that Word must close and asking whether I wish to send a
    report to Microsoft.

    The same thing happens no matter which Form is used. As far as I know the
    Form that contains the particular QueryLoad event is NOT being loaded.

    What could cause this behavior?
      Private Sub  Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
          'Prevent user  from closing with the Close box in the title bar.
          If UnloadMode =  vbFormControlMenu Then
              Cancel = 1
              MsgBox "Please use the  Exit tab to close the Form", _
                  vbInformation + vbOKOnly, "Close  button cannot be used to close
      the Form"
          Else
              Cancel =  0
          End If
      End Sub

  2. #2
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Found the problem.

    On 5 January, I added the OPENFILENAME structure to the sub that
    initializes the class.

    In that structure, I used

    .hwndOwner = frmX.hWnd

    So the form was indeed being loaded every time.

    However, since adding the structure, until yesterday, I had only been
    testing with frmX, not the other forms, so I did not see the problem.

    The solution appears to be to not set .hwndOwner, so I just removed the line

    .hwndOwner = frmX.hWnd

    I guess that UnloadMode gets set to vbFormControlMenu when such a form gets
    unloaded, even tho the Close box was not used.

  3. #3
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Yes, I violated my religion by marking this thread as Solved, but it felt oh so good!!

Posting Permissions

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