Controlling another application from within Access

Sprocket

Registered User.
Local time
Today, 00:23
Joined
Mar 15, 2002
Messages
70
Hi Folks.

I have exhausted my search capabilities on this and can't find an answer - maybe I'm asking the wrong thing.

Hope someone can help with this, its driving me mad.

I'm using Using Windows XP and Access 2003

What I am trying to do is use a third party post-code finder to complete addresses and enter them into my database. I have the following code on a double-click event of the postcode field,

Dim stAppName As String
stAppName = "J:\Quickaddress2005\pro32.315\qapron.exe"
Call Shell(stAppName, 1)

This opens the postcode programme OK. I can enter a search and it returns the address to my database OK. However, as it enters the details it minimises itself to the Taskbar.

My problem is that every time this code runs it opens another copy of the third part programme.

What I want to do is check to see if it the third party programme is already open and if so maximise it.

Any thoughts would be much appreciated


Cheers ... Sprocket
 
I got this code from somewhere but can't reminder, so I don't know who the credit should go to.

Create a module and place the following code into it.

Example of usage:-

If GetCountOfWindows(hWndAccessApp, "Dry Chemical Stores Database") > 1 Then

MsgBox "Please use the instance of 'Dry Chemical Stores Database' that is already opened."

DoCmd.Quit acQuitSaveNone

End If




Option Compare Database
Option Explicit

Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal CCh As Long) As Long
Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long

Public pboolCloseAccess As Boolean

Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDLAST = 1
Public Const GW_HWNDNEXT = 2
Public Const GW_HWNDPREV = 3

Function GetAppName(Lnghwnd As Long)

' This function returns the Caption Text of each window passed to
' it. If a window does not have a Caption bar, then this function
' returns a zero-length string ("")

Dim LngResult As Long
Dim StrWinText As String * 255
Dim LngCCh As Long

LngResult = GetWindowText(Lnghwnd, StrWinText, 255)

GetAppName = Left(StrWinText, LngResult)

End Function

Function GetCountOfWindows(Lnghwnd, StrAppCaption)

' This function counts all instances of an application that are open,
' including any windows that are not visible.
' Arguments: LngHwnd = Any valid window handle.
' StrAppCaption = The window caption to search for.
' Example: GetCountOfWindows(hWndAccessApp,"Microsoft Access")

Dim LngResult As Long
Dim LngICount As Long
Dim StrAppName As String

LngResult = GetWindow(Lnghwnd, GW_HWNDFIRST)

Do Until LngResult = 0

If IsWindowVisible(LngResult) Then

StrAppName = GetAppName(LngResult)

If InStr(1, StrAppName, StrAppCaption) Then

LngICount = LngICount + 1

End If

End If

LngResult = GetWindow(LngResult, GW_HWNDNEXT)

Loop

GetCountOfWindows = LngICount

End Function
 
Can you post the rest of your code? Do you use sendkeys to send keystrokes to the screen?
 
allan57 Thanks for your pointer - I have copied the relevant code into my database and added the following to my proceedure

If GetCountOfWindows(hWndAccessApp, "QuickAddress Pro") = 1 Then

MsgBox "Please use the instance of 'QuickAddress Pro' that is already opened."

Exit Sub

This allows me to open one copy and set required parameters - it can then recognise if I try to open another copy. However it does not deal with the problem of maximizing the existing post-code application window in order to conduct a new search.

KeithG

I don't have any other code on this event at this time. I just want to maximize the post-code application window and enter a search term into this app manually. Maybe in time I can enter the postcode directly into my database and use the "on update" event to trigger an automatic search

Oh how we wish!!

Still looking -- Sprocket
 
Have you tried using sendkeys to send keystokes to the screen?
 
KeithG

Hi KeithG - yes using sendkeys will work up to a point. Using ALT + TAB to cycle with the last application. see code:

If GetCountOfWindows(hWndAccessApp, "QuickAddress Pro") = 1 Then

SendKeys "%{tab}"

Exit sub


However, this fails if I step out of Access to - say answer an email - the cycle is upset and I end up opening my email. OR had you some other sneaky keystroke in mind?

Perhaps I should have said this is on a multiuser database not just my desktop PC, so it needs to work for anyone no matter what other apps they may have open also. I think to make this work in all circumstances I really need to be able to identify the specific instance/window/whatever of the post-code programme.

Still looking ... Sprocket
 
Hi Folks...

Sorry to bring this up again but I am still looking for a solution to this problem.

Regards... Sprocket
 
have you tried the AppActivate function to activate the application? I don't see why it minimizes by itself. There is probably a windows function you can call to maximize it though. I look and see if I can find anything.
 
Allan57

Absolutely brilliant

This combined with your previous post works like a dream.

There is always an easy way to do these things is is just finding it that is difficult. Perhaps I don't ask the question in quite the right way first time.

Thanks to all who contributed, I have learnt so much through this forum

Sprocket ... signing off with a great big smile :D
 
Allan57

Absolutely brilliant

This combined with your previous post works like a dream.

There is always an easy way to do these things is is just finding it that is difficult. Perhaps I don't ask the question in quite the right way first time.

Thanks to all who contributed, I have learnt so much through this forum

Sprocket ... signing off with a great big smile :D
 

Users who are viewing this thread

Back
Top Bottom