PDA

View Full Version : Is Application open



Clifford
12-21-2007, 08:35 AM
I NEED HELP............MS Access 2000 on MS Windows XP
I can open a .PDF file from my MS Access app with the adobe reader. Before I try to move to the next .PDF file ( in my list) I would like to test if the previous file (or the reader Application) is still open and urge the user to close it before opening a new file. Does anyone have any GOOD working code examples that I can use or view.......Thank you VERY much in advance.
cliff (cliff@nac.net)

X-BRichard-X
12-28-2007, 10:57 PM
The reason no one has responded to your issue is because it is NOT an easy issue to tackle successfully without really putting together a creative hack for it.

Here's the problem with VBA relative to this issue. While VBA can do many things well in a programmatic sense, what it really lacks (in the absence of a COM library that I am unaware of) is the ability to effectively manage processes (opened applications), and that's what you need to be able to programmatically develop a solution here.

The SHELL function allows you to OPEN a particular process but not close it.

I had a similar challenge and what I did was to create a separate executable in VB.Net that managed the processes for me and wrote the result directly to the registry which I was able to programmatically access through VBA. That's how I did it......

...However, for you, since you may not know .Net enough to work within its process class, then you are relegated to working within the confines of VBA for this solution. To that end, the first thing I would consider is to connect your PDF file names in your listbox to the SELECTED property of the listbox control then create a Select Case statement for each PDF file in your listbox.

As the user selects a PDF file, programmatically provide a boolean test for the listbox's TAG property (an invaluable control property!) testing whether there is a value there or not. If not, it means it's the first PDF file that the user is attempting to open and you record the file name in the tag property. As the user begins to open a SECOND PDF file (while the previous PDF file is open), the Select Case statement will catch that new file name, and the boolean test I suggested earlier will be performed which will again test for whether or not a value is listed within the listbox TAG property. Of course the boolean test will be positive and it is the contents of THIS property that is bounced back to the user in the form of a message box urging the user to close the previous PDF file before continuing. Once the user closes the PDF file, the NEW PDF file name is populated into the listbox's TAG property and the process continues.

While this solution will work, the inherent problem with it is that there is NO way within VBA to check against whether or not the user ACTUALLY closed the PDF file in question.

This is why when an attempt to control processes ensues within a VBA solution, .Net becomes the viable solution to use as an integrative tool with VBA.

Using the process class in .Net, you can search, open and close processes fairly easily.

Good luck in whatever solution you ultimately pursue.

rconverse
01-13-2008, 12:54 PM
I NEED HELP............MS Access 2000 on MS Windows XP
I can open a .PDF file from my MS Access app with the adobe reader. Before I try to move to the next .PDF file ( in my list) I would like to test if the previous file (or the reader Application) is still open and urge the user to close it before opening a new file. Does anyone have any GOOD working code examples that I can use or view.......Thank you VERY much in advance.
cliff (cliff@nac.net)

Hello,

I have used the below to test if an instance is open.



On Error Resume Next
blnCreated = False
Set XLapp = GetObject(, "Excel.Application")
If XLapp Is Nothing Then
Set XLapp = CreateObject("Excel.Application")
blnCreated = True
Set wbPersonal = XLapp.Workbooks.Open(strPersonalPATH & strPersonalNAME)
Else
Set wbPersonal = XLapp.Workbooks(strPersonalNAME)
End If


Obviously you will want to change out XL for PDF or Acrobat.

HTH
Roger