Watch for a popup?

User avatar
Abraxus
3StarLounger
Posts: 254
Joined: 01 Mar 2010, 17:34
Location: Blue Springs, MO

Watch for a popup?

Post by Abraxus »

Is it possible to have VBA, specifically MS Access VBA, watch for a popup window from another application?

I have another app that does some automation, but sometimes fails. When it does, it pops up an error. Since I don't always watch the PC it runs on, some time may pass before I notice it. I'd like to have some code running to watch for that popup and then have it notify me so I can fix it.

Ideas?

Thanks!

Morgan
Morgan

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15653
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Watch for a popup?

Post by ChrisGreaves »

Abraxus wrote:... but sometimes fails. When it does, it pops up an error.
Would it work if, at the time of error, you had it send you an email, an Instant Message, sound a beep, or something similar?

Years ago I had a similar problem converting old WordPerfect documents in MSWord; 3rd party converters issued non-trappable pop-up boxes.

I thwarted this hold-up by running an Excel job in parallel with the MSWord converter job.
The Excel job checked every 5 minutes to see if the MSWord job's log file had changed.
If no change (in date-last-modified) had occured, the Excel job assumed it was because we were stalled (on a pop-up in MSWord), and issued an alarm.
If the log file HAD changed, Excel issued an APPLICATION.ONTIME (I think that's right) and went to sleep for five minutes.
He who plants a seed, plants life.

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Watch for a popup?

Post by agibsonsw »

Is it not possible to modify the other app so that it does something else (send an emai..?) rather than pop-up a message?

I suspect this would be possible using Win32 APIs to count or log the current windows' handles. That is, to count the number of windows' handles that exist when the process starts, and periodically count them again. This is not really my area, so I don't know if it would be additionally possible to confirm that the new handle/window is a pop-up(?). I'm guessing it would be possible as I (again.. guessing) assume that a window might have a property that could be read to confirm this, or even to determine the size of the new window ;).

Sorry, this is speculation, so I apologise if it is a distraction. Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

PJ_in_FL
5StarLounger
Posts: 1108
Joined: 21 Jan 2011, 16:51
Location: Florida

Re: Watch for a popup?

Post by PJ_in_FL »

How are you interacting with the other application in VBA?

In SAP, I interact through the SAP GUI Scripting Object and set up the error handler to check for a second window in the session I am connecting to. The second window is usually an alert or error pop-up that prevents interacting with the first window until the second window is cleared, producing an object related error (usually the dreaded 1004).

Barring that level of sophistication, can the failing application create a file in a pre-determined location that Access can periodically query?
PJ in (usually sunny) FL

User avatar
Abraxus
3StarLounger
Posts: 254
Joined: 01 Mar 2010, 17:34
Location: Blue Springs, MO

Re: Watch for a popup?

Post by Abraxus »

The only option I have is to watch for the popup. It doesn't create logs that can be watched and I can't change the app as it is a 3rd party app...
Morgan

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Watch for a popup?

Post by agibsonsw »

the code at the bottom of this page can be copied and run from Excel VBA. It produces a list of all open windows, child windows, their class-names and titles. You could periodically run this code, comparing the sets of values returned. With a little effort you could discover which, if any, new windows were opened, and examine its class or title. If you run it when you know that the new window (that you are seeking) is open then you will have a better idea of which information for this is useful to you.

A simpler approach would be to just count how many handles were found, and keep re-checking this count until it increases by one.

But I am not an expert in the Win API. I suspect it might be possible to wait for a message (subscribe to an event of..) the other application, but I don't have sufficient knowledge to pursue this topic.

Sorry if this doesn't help. Good luck.

Here is part of the output that I received:
394184,OfficeTooltip,Run Sub/UserForm (F5),,,,,,,,,,,,,,,,,,
197574,MSO_DROPSHADOW_WINDOW_CLASS,N/A,,,,,,,,,,,,,,,,,,
132036,MSO_DROPSHADOW_WINDOW_CLASS,N/A,,,,,,,,,,,,,,,,,,
66612,tooltips_class32,N/A,,,,,,,,,,,,,,,,,,
65732,CiceroUIWndFrame,TF_FloatingLangBar_WndTitle,,,,,,,,,,,,,,,,,,
65734,CiceroUIWndFrame,CiceroUIWndFrame,,,,,,,,,,,,,,,,,,
66610,tooltips_class32,N/A,,,,,,,,,,,,,,,,,,
65680,tooltips_class32,N/A,,,,,,,,,,,,,,,,,,
262886,tooltips_class32,N/A,,,,,,,,,,,,,,,,,,
983802,BaseBar,N/A,328410,MenuSite,N/A,1377086,ToolbarWindow32,N/A,,,,,,,,,,,,
1114886,BaseBar,N/A,328436,MenuSite,N/A,393976,ToolbarWindow32,N/A,,,,,,,,,,,,
131222,BaseBar,N/A,131224,MenuSite,N/A,131226,SysPager,N/A,131228,ToolbarWindow32,N/A,,,,,,,,,
,,,,,,196918,ToolbarWindow32,N/A,,,,,,,,,,,,
196680,MSCTFIME UI,M,,,,,,,,,,,,,,,,,,
196678,IME,Default IME,,,,,,,,,,,,,,,,,,
65666,tooltips_class32,N/A,,,,,,,,,,,,,,,,,,
65682,tooltips_class32,N/A,,,,,,,,,,,,,,,,,,
131570,WorkerW,N/A,,,,,,,,,,,,,,,,,,
65664,tooltips_class32,N/A,,,,,,,,,,,,,,,,,,
65662,tooltips_class32,N/A,,,,,,,,,,,,,,,,,,
65660,tooltips_class32,N/A,,,,,,,,,,,,,,,,,,
196674,Shell_TrayWnd,N/A,196682,Button,Start,,,,,,,,,,,,,,,
,,,196684,TrayNotifyWnd,N/A,196686,TrayClockWClass,19:22,,,,,,,,,,,,
,,,,,,131190,SysPager,N/A,65656,ToolbarWindow32,Notification Area,,,,,,,,,
,,,,,,65658,Button,N/A,,,,,,,,,,,,
,,,65668,ReBarWindow32,N/A,65674,MSTaskSwWClass,Running Applications,65678,ToolbarWindow32,Running Applications,,,,,,,,,
,,,,,,65672,ToolbarWindow32,Quick Launch,,,,,,,,,,,,
131890,MozillaWindowClass,N/A,,,,,,,,,,,,,,,,,,
197402,MozillaDropShadowWindowClass,N/A,,,,,,,,,,,,,,,,,,
328432,MozillaDropShadowWindowClass,N/A,,,,,,,,,,,,,,,,,,
328420,MozillaDropShadowWindowClass,N/A,,,,,,,,,,,,,,,,,,
65698,tooltips_class32,N/A,,,,,,,,,,,,,,,,,,
66044,tooltips_class32,tooltip_view_,,,,,,,,,,,,,,,,,,
66038,wxWindowClassNR,N/A,66040,CefBrowserWindow,N/A,66042,WebViewHost,N/A,,,,,,,,,,,,
,,,66046,Button,Open Dropbox Menu,,,,,,,,,,,,,,,
65714,SynTrackCursorWindowClass,N/A,,,,,,,,,,,,,,,,,,
65724,IME,Default IME,,,,,,,,,,,,,,,,,,
65722,CicLoaderWndClass,N/A,,,,,,,,,,,,,,,,,,
66450,MSCTFIME UI,M,,,,,,,,,,,,,,,,,,
525046,IME,Default IME,,,,,,,,,,,,,,,,,,
66584,VBFloatingPalette,N/A,,,,,,,,,,,,,,,,,,
66582,VBFloatingPalette,N/A,,,,,,,,,,,,,,,,,,
66580,VBFloatingPalette,N/A,,,,,,,,,,,,,,,,,,
66578,VBFloatingPalette,N/A,,,,,,,,,,,,,,,,,,
66576,VBFloatingPalette,N/A,,,,,,,,,,,,,,,,,,
66600,MsoCommandBarPopup,Debug,,,,,,,,,,,,,,,,,,
66602,MsoCommandBarShadow,Debug,,,,,,,,,,,,,,,,,,
66604,MsoCommandBarShadow,Debug,,,,,,,,,,,,,,,,,,
66606,MsoCommandBarShadow,Debug,,,,,,,,,,,,,,,,,,
66526,wndclass_desked_gsk,Microsoft Visual Basic for Applications - Book1 [running] - [Module1 (Code)],66586,MsoCommandBarDock,MsoDockLeft,,,,,,,,,,,,,,,
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Watch for a popup?

Post by agibsonsw »

PS I ran the code from Excel but it can be modified to run from Access, and then called from, for example, the OnTimer event of a form.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
Jay Freedman
Microsoft MVP
Posts: 1320
Joined: 24 May 2013, 15:33
Location: Warminster, PA

Re: Watch for a popup?

Post by Jay Freedman »

Instead of plowing through a list of all the open windows, you can grab the Spy++ program from http://mdb-blog.blogspot.com/2010/11/mi ... nload.html. When the error message appears, start up Spy++ and use its special cursor to click on the message box. That will tell you enough about it to let you write code that watches for that specific window.