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
David W. Fenton - 18 Jan 2006 13:59 GMT
> 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.
That makes no sense to me. It's impossible without VBA code to
specifically implement it for a user to open multiple instances of a
form. Impossible. So, you don't have to do *anything* to prevent it
except to *not implement it in the first place*.

Signature
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Tom van Stiphout - 19 Jan 2006 03:55 GMT
The writer was referring to two instances of the same *database*,
whereas you are referring to two instances of the same form.
-Tom.
>> 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
[quoted text clipped - 4 lines]
>form. Impossible. So, you don't have to do *anything* to prevent it
>except to *not implement it in the first place*.
How many forms would you like to open? You have a front-end MDE +
back-end MDB? What version of Access? What OS?
With the way modern operating systems have near-limitless memory
available (if needed in a swap file), I think it's impossible to
calculate if you can add one more without crashing.
Rather I would look at the nature of your code. For example I think
you would easily be able to open a few dozen instances of any form in
the Northwind sample application. Perhaps something in your code is
contributing to the crash.
I just wrote some code to open the Orders form in Northwind multiple
times. Access 2003 on WinXP. After 54 instances I got a "Reserved
Error". That's plenty of forms for me...
-Tom.
>Hello
>
[quoted text clipped - 16 lines]
>
>G.Gerard