![]() | |
![]() |
| | Thread Tools | Display Modes |
#11
| |||
| |||
|
|
On 22/11/2010 09:03:18, "Jon Lewis" wrote: Well doesn't my post above cover this? Jon "Phil" <phil (AT) stantonfamily (DOT) co.uk> wrote in message news:ic6uq1$18n$1 (AT) speranza (DOT) aioe.org... Hi Jon Thought it was working, but no lock Here is the code Function fEnumWindows() Dim lngx As Long, lngLen As Long Dim lngStyle As Long, strCaption As String Dim Otherhwnd As Long lngx = apiGetDesktopWindow() 'Return the first child to Desktop lngx = apiGetWindow(lngx, mcGWCHILD) Do While Not lngx = 0 strCaption = fGetCaption(lngx) If Len(strCaption) > 0 Then lngStyle = apiGetWindowLong(lngx, mcGWLSTYLE) 'enum visible windows only If fGetClassName(lngx) = "OMain" Then ' Databases If lngStyle And mcWSVISIBLE Then Debug.Print "Class = " & fGetClassName(lngx), Debug.Print "Caption = " & fGetCaption(lngx), Otherhwnd Otherhwnd = apiFindWindow(fGetClassName(lngx), fGetCaption(lngx)) Debug.Print "OtherDb = " & Otherhwnd Debug.Print "ThisDb = " & GetAccesshWnd() '******** 'OMain is the class name of a main Access window so if this Window 's handle ********** '******** 'differs from your hWndAccessApp then lngX is the handle you want***************** If lngx <> hWndAccessApp Then SendMessage lngx, SW_SHOWMAXIMIZED, 0, 0 Application.Quit End If End If End If End If lngx = apiGetWindow(lngx, mcGWHWNDNEXT) Loop End Function Problem is that if any other Access DB is open, this DB (Clubs) immediately quits. The duff line is If lngx <> hWndAccessApp Then I Only want to quit the application if someone tries to open up a second copy of the Clubs database Thanks, Phil Hi Jon Have pasted your code in exactly as your previous post. This is in my "Clubs" Db. If I have my "Questions" Db open, then try to open my "Clubs" Db, it opens and immediately closes. if I comment out the Application'Quit line, the debug gives me Class = OMain Caption = WFYC Club DB Phil 0 OtherDb = 788380 ThisDb = 788380 Class = OMain Caption = Microsoft Access - Questionnaire : Database (Access 2007) 788380 OtherDb = 852634 Any further thoughts? Thanks, Phil |
#12
| |||
| |||
|
|
"It occurs to me that the code will find the handle for any Access application open so you may want to compare the returns from fGetcaption to make sure it's the relevant one." This is what I suggested 2 posts ago - did you do this? (I assumed that you would be able to write appropriate code) I posted the fGetcaption code but assumed that you would include what you needed in the main routine to compare the return from this function to (in your case) whatever the title is of your "Clubs" db is to ensure you get the handle to another instance of "Clubs" and not just any open db. Jon Thanks Jon, all sorted now, and working perfectly |
#13
| |||
| |||
|
|
On 22/11/2010 13:45:41, "Jon Lewis" wrote: "It occurs to me that the code will find the handle for any Access application open so you may want to compare the returns from fGetcaption to make sure it's the relevant one." This is what I suggested 2 posts ago - did you do this? (I assumed that you would be able to write appropriate code) I posted the fGetcaption code but assumed that you would include what you needed in the main routine to compare the return from this function to (in your case) whatever the title is of your "Clubs" db is to ensure you get the handle to another instance of "Clubs" and not just any open db. Jon Thanks Jon, all sorted now, and working perfectly Phil |
![]() |
| Thread Tools | |
| Display Modes | |
| |