Results 1 to 4 of 4

Thread: Forcibly terminate execution of an EXE application

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Location
    Where do you want me to be...
    Posts
    10

    Question Forcibly terminate execution of an EXE application

    I have an exe which generates some word reports. I want to terminate the execution of this exe when i click a cancel button. I am not able to get it working

    I have used this sub routine to stop execution

    Sub KillPrint()
    Set wrd = Nothing
    MsgBox "Print Cancelled!"
    End
    End Sub


    I am not able to set the focus on the cancel button when the printing of the data in the word document is started..
    I am using the code

    frmPrint.setfocus for the same

    I need help:
    1. To get focus on the Cancel button
    2. To get it to kill the execution of the program
    Harshad

  2. #2
    New Member
    Join Date
    Feb 2003
    Location
    Delhi-India
    Posts
    10
    use doevents before starting the code, this will enable you to receive events from the command button inbetween.

    Ritesh

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    First thing - your KillPrint sub doesn't make any attempt to close Word, just destroy the link to it. Try this instead:
    VB Code:
    1. Sub KillPrint()
    2.  
    3. On Error Resume Next    
    4. wrd.DisplayAlerts = 0 'do not show Word messages (such as "printing hasn't finished yet")
    5. wrd.Quit False        'Quit word (without saving changes to documents)
    6.  
    7. Set wrd = Nothing
    8. MsgBox "Print Cancelled!"
    9.  
    10. End   'There are lots of arguments for not using End - unloading forms would be better.
    11.  
    12. End Sub


    And as far as enabling you cancel button goes, riteshtandon was on the right track.. DoEvents is what you need. Just put it into your code in several places, not just at the start - especially within loops and before+after lines of code that take a long time to execute.

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2002
    Location
    Where do you want me to be...
    Posts
    10
    Thanx a lot to both of u..

    It worked...
    Harshad

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