Results 1 to 9 of 9
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097

    How to close WORD following a Shell

    I have a continuous form that includes WORD document file names. The user clicks on the record selector and my code opens the corresponding doc file via Shell so the user can cut/paste a particular piece of information into a text-box within the current record. What I'd like to do in the After Update event for the receiving text box is to automatically close WORD.



    Anyone know how to do that?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Never needed it, but see if this works for you:

    http://access.mvps.org/access/api/api0025.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097
    Hi Paul,

    I'm puzzled. I ran the code to get the class name and then the code that closes the desired app. What's puzzling is it worked the first time but I couldn't get the app to close in all attempts subsequently.

    I ran the code in debug both with providing the class name of the app when the app was in fact open and also when it was not open. The code took the path as one would expect, yet the app didn't close when the proper class name was provided.

    Maybe someone else will see this thread and recognize the problem.

    Thanks,
    Bill
    (PS) Many folks in Reno Thursday wearing shorts and tank-tops............this is February!!!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Cooking up a pot of pasta sauce right now, so can't get to a computer. Will try to play later.

    Yes, it's been like late spring down here, though getting chilly again now.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097
    I tried running Dev Ashish's code again. And, while observing code execution in Debug, it seems to recognize the class name and ID of WORD but DOES NOT close the app. Maybe a fresh set of eyes will see where things aren't working?
    Bill

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Can Terminate an app without API calls. However, if more than one Word document is open, all instances of Word would have to be closed because there is no way to know which one is what document. http://www.computerperformance.co.uk...ocess_stop.htm
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097
    Hi June,
    I guess I don't know how to employ a VB Script into a VBA module in Access. Below is my attempt: (What's with the strComputer "."?)

    Click image for larger version. 

Name:	ProKill.jpg 
Views:	12 
Size:	143.5 KB 
ID:	19844

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Bill, this seems to work:
    In my module...
    Code:
    Option Compare Database
    Option Explicit
    
    '******************** Code Start **************************
    ' This code was originally written by Dev Ashish.
    ' It is not to be altered or distributed,
    ' except as part of an application.
    ' You are free to use it in any application,
    ' provided the copyright notice is left unchanged.
    '
    ' Code Courtesy of
    ' Dev Ashish
    '
    Private Declare Function apiGetComputerName Lib "kernel32" Alias _
                                                "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    
    Function fOSMachineName() As String
        'Returns the computername
        Dim lngLen As Long, lngX As Long
        Dim strCompName As String
        lngLen = 16
        strCompName = String$(lngLen, 0)
        lngX = apiGetComputerName(strCompName, lngLen)
        If lngX <> 0 Then
            fOSMachineName = Left$(strCompName, lngLen)
        Else
            fOSMachineName = ""
        End If
    End Function
    '******************** Code End **************************
    
    
    
    Public Sub Kill_WinWord()
        ' ProcessKillLocal.vbs
        ' Sample VBScript to kill a program
        ' Author Guy Thomas http://computerperformance.co.uk/
        ' Version 2.7 - December 2010
        ' ------------------------ -------------------------------'
        Dim objWMIService, objProcess, colProcess
        Dim strComputer, strProcessKill
    
        'Your computer name - can hard code it or use fOSMachineName()
        'strComputer = "Yoda"
        strComputer = fOSMachineName
        strProcessKill = "'Winword.exe'"
    
        Set objWMIService = GetObject("winmgmts:" _
                                    & "{impersonationLevel=impersonate}!\\" _
                                    & strComputer & "\root\cimv2")
    
        Set colProcess = objWMIService.ExecQuery _
                         ("Select * from Win32_Process Where Name = " & strProcessKill)
        For Each objProcess In colProcess
            objProcess.Terminate     '<<= no parens
        Next
        '    WScript.Echo "Just killed process " & strProcessKill _
             '               & " on " & strComputer
        '    WScript.Quit
        ' End of WMI Example of a Kill Process
    End Sub

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    2,097
    EXCELLENT!!!!

    Thanks Steve,
    Bill

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

Similar Threads

  1. Replies: 4
    Last Post: 01-31-2014, 11:47 AM
  2. From Access unable to close Word with VBA
    By jsbotts in forum Programming
    Replies: 11
    Last Post: 01-13-2012, 05:31 PM
  3. wait and shell
    By maxbre in forum Programming
    Replies: 19
    Last Post: 11-03-2011, 11:10 AM
  4. Using Shell in VBA
    By ghutche in forum Programming
    Replies: 7
    Last Post: 03-17-2011, 10:13 AM
  5. Replies: 1
    Last Post: 12-21-2005, 12:27 AM

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