how can i close access window?
Printable View
how can i close access window?
How did you open it?
VBKNIGHT:
Here how we close an external application.
Code:Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SYSCOMMAND = &H112
Private Const SC_CLOSE = &HF060&
Private xhWnd As Long
Private Sub CloseExtApplication()
xhWnd = FindWindow(0&, "Access Windows name")
If xhWnd <> 0 Then SendMessage xhWnd, WM_SYSCOMMAND, SC_CLOSE, 0&
End Sub
You also need to Destroythe window.
Code:Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Const WM_CLOSE = &H10
Private Sub Command1_Click()
Dim hWnd_App As Long
hWnd_App = FindWindowEx(0, 0, "WindowClass", "WindowName")
SendMessage hWnd_App, WM_CLOSE, 0, 0
DestroyWindow hWnd_App
End Sub