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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I close another application ( Adobe Acrobat) from Access?

Status
Not open for further replies.

jeisch

MIS
May 30, 2003
23
0
0
US
I am setting up an automated process using Access 97 on a NT 4.0 PC to create PDF files from reports using the Adobe Distiller. I am then attaching the PDF files to Winfax or Outlook , and sending them to customers. When Winfax uses the PDF files, it opens Adobe Acrobat to convert the files to the Winfax format, and then leaves Adobe open with the last converted file up.

When the application tries to delete that file, I get an error because it is still in use by another application(Acrobat). How can I identify the Acrobat application running, and either close the file, or preferrably exit the application?

Thanks

 
I reckon you have to close the applications in your VBA code properly.

i.e. appName.quit
 
jeisch,
I have never heard of using appName for anything except discovering a browser name, so dhaveedh, if you could explain a little more clearly how this works, I'd enjoy learning about it......

In the meantime, here's another way (which I use to kill this annoy-o-gram that my employer sends each time I log in. It is actually a VB program that I run in my startup, but there's no reason you could not run it in VBA.

You can take out the sleep stuff, I am just including it fyi. The only other thing you really need to change is where it says:

hWnd = findwindow(vbNullString, " KDOT COMPUTERS AND NETWORKS ARE FOR OFFICIAL BUSINESS")

Change the " KDOT COMPUTERS...." to "ADOBE ACROBAT"

Then it will find the handle of the thread that has "ADOBE ACROBAT" in its title bar, and close the app window, which will end the application.

'......................This part of the code goes
' in the general declarations
Option Explicit

Public Const WM_CLOSE = &H10

Declare Function findwindow Lib "user32.dll" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

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



'..................... This is just a standard private sub
Private Sub KillApp()
Dim hWnd As Long
Dim intCtr As Integer

' Wait for up to 1 minute to find warning.exe window handle
For intCtr = 1 To 120
hWnd = findwindow(vbNullString, " KDOT COMPUTERS AND NETWORKS ARE FOR OFFICIAL BUSINESS")

Select Case hWnd

Case 0
' Window handle not found
' Wait 500 milliseconds, then look again
Sleep 500
DoEvents

Case Else
' Window handle found
' Leave warning message up for 5 seconds
Sleep 5000

'Close the App Window (which ends the app)
Call SendMessage(hWnd, WM_CLOSE, 0&, 0&)
Exit For
End Select
Next

End Sub

This code works under Win98, Win2K, WinNT4.0, WinXP.

Good luck,
Tranman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top