Solved

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

Posted on 2009-04-01
3
403 Views
Last Modified: 2012-05-06
What is the VBA to close an external database after appending to it and then compact it?
0
Comment
Question by:indyng
  • 2
3 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24038839
how are you appending to it? and I assume you are programmatically compacting it?
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 total points
ID: 24038882
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question