Results 1 to 7 of 7
  1. #1
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228

    Terminating a Process with VBA


    I looked up some code to terminate a process using VBA and it loops through processes and finds what I'm looking for, however the terminate command is "Not Found".

    Can anybody clarify what's wrong with the code? Do I need a reference library activated?

    Code:
    Public Function test1()Dim cProc As Variant, oProc As Object
    
    
    Set cProc = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("Select * From Win32_Process", , 48)
    
    
    For Each oProc In cProc
        If oProc.name = "iexplore.exe" Then oProc.Terminate
    Next
    
    
    Set oServ = Nothing
    Set cProc = Nothing
    
    
    End Function

  2. #2
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    Issue resolved.

  3. #3
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    Could you just use End to get out of that loop?

    For Each oProc In cProc
    If oProc.name = "iexplore.exe" Then End
    Next

    Or Jump out of it:

    For Each oProc In cProc
    If oProc.name = "iexplore.exe" Then Goto Jump1
    Next

    Jump1:

  4. #4
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,463
    Quote Originally Posted by kdbailey View Post
    Issue resolved.
    How did you fix?

  5. #5
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    I'm running a loop in which ie opens and closes X times. Some reason it would not close the process each time. Thus the reason for needing to check and terminate the processes outside the normal close statement.

    TWhen it began running through each process from the above code, it would find the process prior to it fully closing. When it went to terminate it, it was no longer there.

    I just created an error handler for this specific situation.

  6. #6
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    A call to a pause function is often useful in cases like this:


    Code:
    Pause (2)
    
    Public Function Pause(intSecs As Integer)
    Dim Start As Variant
    Start = Timer
    Do While Timer < Start + intSecs
        DoEvents
    Loop
    End Function
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    Posts
    228
    I went back and forth with the idea of doing a pause or error handler. This morning the update ran without problem, looks to be working.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Planning Process
    By bleyden in forum Access
    Replies: 2
    Last Post: 08-09-2016, 07:31 PM
  2. What function to use this process
    By azhar2006 in forum Forms
    Replies: 2
    Last Post: 10-05-2014, 02:20 PM
  3. Ask a process amounts
    By azhar2006 in forum Queries
    Replies: 4
    Last Post: 01-14-2014, 01:06 PM
  4. Help with Normalisation Process
    By supermessiah in forum Database Design
    Replies: 2
    Last Post: 02-26-2013, 12:36 PM
  5. Need help to simplify this process
    By shanea.kr in forum Access
    Replies: 1
    Last Post: 07-10-2012, 01:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums