Results 1 to 2 of 2

Thread: Window objects not clossing after unload

  1. #1

    Thread Starter
    Addicted Member SkyCoder's Avatar
    Join Date
    Oct 2003
    Location
    Moon Crater 25
    Posts
    183

    Window objects not clossing after unload

    After I unload my project the application doesnt close. ie when you go to task manager you can still see the app running. Is there a function available in VB that can do this or what other method can i use. (Im ussing a mdi with child forms & even if i unload each object in script the project still doesnt close)

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    The program won't shutdown completely because some object some where still contains a valid reference and has not been terminated.

    Make sure all objects are terminated using Set ObjectName = Nothing. Also, if the object requires it, call its Close or Quit method.

    For example, the following code will cause a hidden instance of Microsoft Word to be created everytime this program is executed. Every instance of Word will remain active, even though we set the object to nothing, until the computer is rebooted or MS Word is opened and then closed. This is because the Word object requires a call to its Quit method.

    The point is make sure you terminate all object instances properly. Don't rely on VB to handle everything.

    VB Code:
    1. Option Explicit
    2. Private objWord As Word.Application
    3.  
    4. Private Sub Form_Load()
    5.     Set objWord = New Word.Application
    6. End Sub
    7.  
    8. Private Sub Form_Unload(Cancel As Integer)
    9.     Set objWord = Nothing
    10.     Set Form1 = Nothing
    11. End Sub

    For those who are thinking of suggesting it, using End in this case will not close the runaway MS Word process.

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