Re: Multiple Instance of a form limite
- From: "Pachydermitis" <praesagus@xxxxxxxxx>
- Date: 17 Jan 2006 19:10:38 -0800
G,
I dont know about your second question, but I had to do the opposite of
the first to keep a user from opening two instances of a database. The
solution should work for you with modification. It's a little on the
hacky side, but hey. :) For forms, EnumChildWindows might work better
for you.
Have fun
Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" _
(ByVal hWnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As
Long, ByVal lParam As Long) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd
As Long) As Long
Private byDatabasesOpen As Byte 'The number of instances of
this db open on this machine
Private strAppTitle As String 'The title of this
DB
Private hOtherOpenApp As Long 'handle of the other open
db if there is one
Public Function TestForInstances() As Boolean
'*************************************************************************
' Author Daniel Tweddell
' Date 12/05/02
' Revision
'
' Tests to see if other instances of this database are already open.
If so
' we switch to the other and close this one.
' returns true if there is another instance
'*************************************************************************
If Not bShowDebug Then On Error GoTo Err_Function
byDatabasesOpen = 0
Dim strName As String * 255
GetWindowText Application.hWndAccessApp, strName, 255 'get this
dbs name
strAppTitle = Trim(strName)
EnumWindows AddressOf WndEnumProc, 0
If byDatabasesOpen Then 'will
register as true if > 0
SetForegroundWindow hOtherOpenApp 'focus on
the open db
TestForInstances = True
End If
Exit Function
Err_Function:
errHandler Err.Number, Err.Description, "TestForInstances()",
bSilent
End Function
Public Function WndEnumProc(ByVal hWnd As Long, ByVal lParam As Long)
As Long
'*************************************************************************
' Author Daniel Tweddell
' Date 12/05/02
' Revision
'
' callback for the EnumWindows api. Tests the existing windows against
' this one and returns a handle and a count of same named dbs
'*************************************************************************
If Not bShowDebug Then On Error GoTo Err_Function
Const iSuccess As Integer = 1
Dim strName As String * 255
Dim lSuccess As Long
lSuccess = GetWindowText(hWnd, strName, 255) 'get the name
of the window
If lSuccess <> 0 Then 'see if got
anything
If strAppTitle = Trim(strName) Then 'test it
against our window's name
If hWnd <> Application.hWndAccessApp Then 'make sure it's
not our app
byDatabasesOpen = byDatabasesOpen + 1 'count
hOtherOpenApp = hWnd 'get the other
app's handle
End If
End If
End If
WndEnumProc = iSuccess
Exit Function
Err_Function:
errHandler Err.Number, Err.Description, "WndEnumProc()"
End Function
.
- Follow-Ups:
- Re: Multiple Instance of a form limite
- From: David W. Fenton
- Re: Multiple Instance of a form limite
- References:
- Multiple Instance of a form limite
- From: GGerard
- Multiple Instance of a form limite
- Prev by Date: A2K - update query needed
- Next by Date: A few more questions - saving, canceling, object control
- Previous by thread: Multiple Instance of a form limite
- Next by thread: Re: Multiple Instance of a form limite
- Index(es):
Relevant Pages
|