Results 1 to 10 of 10

Thread: Close an App

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Close an App

    hello,

    unload me is not sufficent for what I am doing, I really need to replicate the action caused when the user clicks the close "X" at the top right of the form,

    is it possible to do this programaticly?

    thanks.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Close an App

    what does unload me do then?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Re: Close an App

    well just ulonads the current app, also i i use unload frm1, unload frm2 etc i dont get the desired effect.

  4. #4
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Close an App

    End will immediately pull the plug on your program.
    But it is not a very good way.

    You can use Unload for any form, not just the one that is calling it.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Re: Close an App

    End not supported by dll is the error i get, presumably cause its not an exe.?

  6. #6
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Close an App

    What effect do you want to replicate??

    This won't close the form:
    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.     Cancel = 1
    3. End Sub
    Is this what you're after? Also, End works also in the IDE.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Re: Close an App

    thanks, but all i am trying to do is programaticly make the app beleive that the user has clicked the close cross.

  8. #8
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Close an App

    "Unload Me" will do it. It will fire the Query_Unload event:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     Unload Me
    5. End Sub
    6.  
    7. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    8.     If UnloadMode = vbFormCode Then
    9.         MsgBox "Form was closed through the code.", vbInformation
    10.     End If
    11. End Sub

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Sep 2006
    Posts
    116

    Re: Close an App

    thanks

  10. #10
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Close an App

    Here are some other constants:
    VB Code:
    1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    2.     Select Case UnloadMode
    3.         Case vbFormControlMenu
    4.             MsgBox "Close command from Control menu or X button."
    5.         Case vbFormCode
    6.             MsgBox "Unload statement from code."
    7.         Case vbAppWindows
    8.             MsgBox "Windows session ending."
    9.         Case vbAppTaskManager
    10.             MsgBox "Task Manager close."
    11.         Case vbFormMDIForm
    12.             MsgBox "MDI parent is closing."
    13.         Case vbFormOwner
    14.             MsgBox "Owner is closing."
    15.     End Select
    16. End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width