• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 414
  • Last Modified:

What is the VBA to close an external database after appending to it and then compact it?

What is the VBA to close an external database after appending to it and then compact it?
0
indyng
Asked:
indyng
  • 2
1 Solution
 
rockiroadsCommented:
how are you appending to it? and I assume you are programmatically compacting it?
0
 
rockiroadsCommented:
we could post a message to it saying to close it

if you set a title to your msaccess window (Tools/Startup), you can try find it and send a close message

eg add this lot to a module


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, lParam As Any) As Long

Const WM_CLOSE = &H10

Public Sub FindAndCloseApp()

    Dim lHandle As Long

'Find a window called Fred    
    lHandle = FindWindow(vbNullString, "Fred")
   
   
    If lHandle > 0 Then
        PostMessage lHandle, WM_CLOSE, 0&, 0&
    End If

End Sub
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now