Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I Close another database? 2

Status
Not open for further replies.

AccessGuruCarl

Programmer
Jul 3, 2004
471
US
I have a database(Update Utility) that checks the directory for the .ldb file, If it's there I want to be able to give the user the ability to close the open db from the utility db, so I can delete it and replace it with the new version.

Thanks

AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
I'd put a table in the database you want to close with a single field. Make the field a Yes/No data type. Have a hidden form with a timer event running to check the table for a True value. If it detects a True value then run Application.Quit, else do nothing. This table should only ever have one record.

Link this table into UpdateUtility. Update the table with a True value if the LDB file is found.

Ed Metcalfe.

Please do not feed the trolls.....
 
You may find this interesting, if your application has a title:

Code:
Option Explicit
'Modified from: [URL unfurl="true"]http://support.microsoft.com/kb/176391[/URL]

      Private Declare Function WaitForSingleObject Lib "kernel32" _
         (ByVal hHandle As Long, _
         ByVal dwMilliseconds As Long) As Long

      Private Declare Function FindWindow Lib "user32" _
         Alias "FindWindowA" _
         (ByVal lpClassName As String, _
         ByVal lpWindowName As String) As Long

      Private Declare Function PostMessage Lib "user32" _
         Alias "PostMessageA" _
         (ByVal hwnd As Long, _
         ByVal wMsg As Long, _
         ByVal wParam As Long, _
         ByVal lParam As Long) As Long

      Private Declare Function IsWindow Lib "user32" _
         (ByVal hwnd As Long) As Long

      Private Declare Function OpenProcess Lib "kernel32" _
         (ByVal dwDesiredAccess As Long, _
         ByVal bInheritHandle As Long, _
         ByVal dwProcessId As Long) As Long
      
      Private Declare Function GetWindowThreadProcessId Lib "user32" _
         (ByVal hwnd As Long, _
         lpdwProcessId As Long) As Long

      'Constants that are used by the API
      Const WM_CLOSE = &H10
      Const INFINITE = &HFFFFFFFF
      Const SYNCHRONIZE = &H100000

       Sub CloseApp_Click()
      'Closes Windows Calculator
         Dim hWindow As Long
         Dim hThread As Long
         Dim hProcess As Long
         Dim lProcessId As Long
         Dim lngResult As Long
         Dim lngReturnValue As Long

         hWindow = FindWindow(vbNullString, "[b]Title Of Application[/b]")
         hThread = GetWindowThreadProcessId(hWindow, lProcessId)
         hProcess = OpenProcess(SYNCHRONIZE, 0&, lProcessId)
         lngReturnValue = PostMessage(hWindow, WM_CLOSE, 0&, 0&)
         lngResult = WaitForSingleObject(hProcess, INFINITE)

         'Does the handle still exist?
         DoEvents
         hWindow = FindWindow(vbNullString, "[b]Title Of Application[/b]")
         If IsWindow(hWindow) = 1 Then
            'The handle still exists. Use the TerminateProcess function
            'to close all related processes to this handle. See the
            'article for more information.
            MsgBox "Handle still exists."
         Else
            'Handle does not exist.
            MsgBox "All Program Instances Closed."
         End If
      End Sub
 
Nice find Remou. Have a star.

Ed Metcalfe.

Please do not feed the trolls.....
 
After serveral searches, I found something similiar to Remou... post. Nice find at MS... I couldn't find anything closely related, and I knew it was possible with an API call.

Here's a star, as well.

AccessGuruCarl
Programmers helping programmers
you can't find a better site.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top