[AccessD] Same FE open twice (or more)

Mark A Matte markamatte at hotmail.com
Thu Jan 31 14:21:59 CST 2008


Sorry John,

Forgot to include all of the API stuff...

Mark A. Matte

****************START FROM MODULE**********************
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 Const GW_HWNDFIRST = 0
      Public Const GW_HWNDLAST = 1
      Public Const GW_HWNDNEXT = 2
      Public Const GW_HWNDPREV = 3
      
  
      ' 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 ("")

      Function GetAppName(Lnghwnd As Long)
         Dim LngResult As Long
         Dim StrWinText As String * 255
         Dim LngCCh As Long
         LngResult = GetWindowText(Lnghwnd, StrWinText, 255)
         GetAppName = left(StrWinText, LngResult)
         GetAppName = left(GetAppName, 5)
      End Function

      ' 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")
      Function GetCountOfWindows(Lnghwnd, StrAppCaption)
         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)
               StrAppCaption = left(StrAppCaption, 5)
               If InStr(1, StrAppName, StrAppCaption) Then
                  LngICount = LngICount + 1
               End If
            End If
            LngResult = GetWindow(LngResult, GW_HWNDNEXT)
         Loop
         GetCountOfWindows = LngICount
         End Function
****************END FROM MODULE**********************



> From: jwcolby at colbyconsulting.com
> To: accessd at databaseadvisors.com
> Date: Thu, 31 Jan 2008 14:43:35 -0500
> Subject: Re: [AccessD] Same FE open twice (or more)
>
> Mark,
>
> There are constants in there that need to be supplied (I don't have them)
>
> GW_HWNDFIRST
> GW_HWNDNEXT
>
>
>
> John W. Colby
> Colby Consulting
> www.ColbyConsulting.com
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Mark A Matte
> Sent: Thursday, January 31, 2008 2:02 PM
> To: Access Developers discussion and problem solving
> Subject: Re: [AccessD] Same FE open twice (or more)
>
>
>
> John,
>
> Several years ago I needed to limit how many times a user could open the
> front end at the same time. I used a call to count the windows open
> everytime the app was launched. I believe you could do the same...but
> instead of not allowing...just logging it. Below is copied from A97.
> fyi...in the example below the app name started with 'MANCR'(need to know
> what you're counting and why I used "StrAppCaption = left(StrAppCaption, 5)"
> to limit to 5 char...)
>
> Let me know,
>
> Thanks,
>
> Mark A. Matte
>
> ********************START*************
> Private Sub Form_Open(Cancel As Integer)
> If GetCountOfWindows(hWndAccessApp, "MANCR")> 1 Then
> Cancel = True
> msgbox "Please use the instance of MANCR that is " _
> & "already open."
> DoCmd.Quit acQuitSaveNone
> End If
> End Sub
>
> ' 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")
> Function GetCountOfWindows(Lnghwnd, StrAppCaption)
> 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)
> StrAppCaption = left(StrAppCaption, 5)
> If InStr(1, StrAppName, StrAppCaption) Then
> LngICount = LngICount + 1
> End If
> End If
> LngResult = GetWindow(LngResult, GW_HWNDNEXT)
> Loop
> GetCountOfWindows = LngICount
> End Function
>
> ********************END*************
>
>> From: jwcolby at colbyconsulting.com
>> To: accessd at databaseadvisors.com
>> Date: Thu, 31 Jan 2008 12:19:55 -0500
>> Subject: Re: [AccessD] Same FE open twice (or more)
>>
>> In fact I do not want to prevent the user from opening it twice,
>> unless it is causing a problem which I haven't determined yet. I just
>> want to see the count of a user in a database or something like that.
>>
>>
>> John W. Colby
>> Colby Consulting
>> www.ColbyConsulting.com
>> -----Original Message-----
>> From: accessd-bounces at databaseadvisors.com
>> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Gustav
>> Brock
>> Sent: Thursday, January 31, 2008 12:07 PM
>> To: accessd at databaseadvisors.com
>> Subject: Re: [AccessD] Same FE open twice (or more)
>>
>> Hi John
>>
>> That is quite easy if you can persuade the users to launch your app
>> via a shortcut (and if you read the command line when launching the
>> app, you can quit if no params exists - see recent thread on this)
>> which forces the frontend to be opened exclusively. If opened already,
>> catch that error and display a message.
>>
>> /gustav
>>
>>>>> jwcolby at colbyconsulting.com 31-01-2008 17:48>>>
>> Is there any way to discover that a user has opened the database more
>> than one time? I have users who do this, and while I don't care, I
>> think that it might be causing issues. I have built a rather elaborate
>> error logging system to log error number, error message, code module,
>> function, line number, workstation, user, time and date. I have the
>> majority of errors coming from specific users and am trying to
>> discover why. Some of them have mentioned that they do use the FE
>> opened more than once at a time so I want to check if these specific
>> users are doing that at the instance that the error occurs.
>>
>> John W. Colby
>> Colby Consulting
>> www.ColbyConsulting.com
>>
>>
>> --
>> AccessD mailing list
>> AccessD at databaseadvisors.com
>> http://databaseadvisors.com/mailman/listinfo/accessd
>> Website: http://www.databaseadvisors.com
>>
>> --
>> AccessD mailing list
>> AccessD at databaseadvisors.com
>> http://databaseadvisors.com/mailman/listinfo/accessd
>> Website: http://www.databaseadvisors.com
>
> _________________________________________________________________
> Connect and share in new ways with Windows Live.
> http://www.windowslive.com/share.html?ocid=TXT_TAGHM_Wave2_sharelife_012008
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com

_________________________________________________________________
Helping your favorite cause is as easy as instant messaging. You IM, we give.
http://im.live.com/Messenger/IM/Home/?source=text_hotmail_join



More information about the AccessD mailing list