Results 1 to 8 of 8

Thread: how to close Access aplication if is opened

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,957

    how to close Access aplication if is opened

    How to close Access aplication if is opened?

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,717

    Re: how to close Access aplication if is opened

    The first thing that I would try is clicking in the X in the right top of the window.

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    10,918

    Re: how to close Access aplication if is opened

    If that doesn't work, right-click your taskbar, select task manager, select Access, right-click it, and say 'End Task'.

    Now, if you want to do it from VB6, there are several posts that have discussed how to kill a task, some that I have posted. But I'll let you search for those. Do you need instructions on how to search?
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  4. #4
    Lively Member
    Join Date
    Jan 2025
    Posts
    72

    Re: how to close Access aplication if is opened

    Solution 1 shows how to close the application:
    Code:
    Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As Long) As Long
    Declare Function PostMessageA Lib "user32" (ByVal hWnd As Long, ByVal wMsg As Long, _
                        ByVal wParam As Long, _
                        ByVal lParam As Long) As Long
    
     
    
    Sub CloseAccess()
     
        Const WM_CLOSE = 16
        Dim hWnd As Long
        hWnd = FindWindowA("OMAIN", 0)
        If hWnd <> 0 Then
           PostMessageA hWnd, WM_CLOSE, 0, 0
        End If
    End Sub
    To terminate the processus;
    Code:
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Process")
    For Each objItem In colItems
        If StrComp(objItem.Name, "MsAccess.exe", vbTextCompare) = 0 Then
          objItem.Terminate
      End If
      
    Next

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,957

    Re: how to close Access aplication if is opened

    Quote Originally Posted by anycoder View Post
    Solution 1 shows how to close the application:
    Code:
    Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As Long) As Long
    Declare Function PostMessageA Lib "user32" (ByVal hWnd As Long, ByVal wMsg As Long, _
                        ByVal wParam As Long, _
                        ByVal lParam As Long) As Long
    
     
    
    Sub CloseAccess()
     
        Const WM_CLOSE = 16
        Dim hWnd As Long
        hWnd = FindWindowA("OMAIN", 0)
        If hWnd <> 0 Then
           PostMessageA hWnd, WM_CLOSE, 0, 0
        End If
    End Sub
    To terminate the processus;
    Code:
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Process")
    For Each objItem In colItems
        If StrComp(objItem.Name, "MsAccess.exe", vbTextCompare) = 0 Then
          objItem.Terminate
      End If
      
    Next
    ITS RIGHT?

    Code:
    Declare Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As Long) As Long
    Declare Function PostMessageA Lib "user32" (ByVal hWnd As Long, ByVal wMsg As Long, _
                        ByVal wParam As Long, _
                        ByVal lParam As Long) As Long
    
     
    
    Sub CloseAccess()
     
        Const WM_CLOSE = 16
        Dim hWnd As Long
        hWnd = FindWindowA("OMAIN", 0)
        If hWnd <> 0 Then
           PostMessageA hWnd, WM_CLOSE, 0, 0
        End If
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_Process")
    For Each objItem In colItems
        If StrComp(objItem.Name, "MsAccess.exe", vbTextCompare) = 0 Then
          objItem.Terminate
      End If
      
    Next
    End Sub

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,753

    Re: how to close Access aplication if is opened

    But why do you need programmatically force a shutdown of Access?

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,957

    Re: how to close Access aplication if is opened

    RESOLVED , TKS TO THE ALL.

    Public Sub ChiudiMSAccess()

    Dim objWMI As Object
    Dim colProc As Object
    Dim PROC As Object, VERO As Boolean

    Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
    Set colProc = objWMI.ExecQuery("SELECT * FROM Win32_Process WHERE Name='MSACCESS.EXE'")

    VERO = (colProc.Count > 0)

    If VERO = True Then
    For Each PROC In colProc
    PROC.Terminate
    Next
    End If

    End Sub

  8. #8
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,277

    Re: how to close Access aplication if is opened

    Quote Originally Posted by Arnoutdv View Post
    But why do you need programmatically force a shutdown of Access?
    Probably because it's blocking his program
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

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