Detecting and Closing an Activex Application from MS Access

Posted on 1998-10-15
Last Modified: 2010-04-30
I have created an ActiveX EXE that pops up a form which maintains a status...I can sucessfully invoke the application, as well as manipulate the data in the ActiveX application from MS Access.  What I would like to be able to do is detect whether or not the ActiveX application is running, and if it is, send a command from MS Access to the ActiveX application to close down.  
Question by:dhoule
  • 2
  • 2
LVL 13

Accepted Solution

Mirkwood earned 50 total points
ID: 1440036
How I would do it is search for the window using FindWindowEx. If the window is found I would close it using SendMessage.

hWndApp = FindWindow("ThunderForm", <title>")
if (hwndapp <> 0) then
   SendMessage (hwndApp, WM_CLOSE, 0, byval 0)

Public Const WM_CLOSE = &H10

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

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

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


Author Comment

ID: 1440037
That worked great, thanks.  How would I go about controlling MINIMIZE and RESTORE?  The same way? &H?

LVL 13

Expert Comment

ID: 1440038
Yep, same way. Send WM_SIZE messages, the wParam must be a value between 0 and 16 I think.

Author Comment

ID: 1440039
Thank you for your help.

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now