By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,677 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,677 IT Pros & Developers. It's quick & easy.

Multiple Instance of a form limite

P: n/a
Hello

I have a program where the user can open as many instances of a form as the
user wants.

The only limit to how many instances can be opened is determined by the
limit of the computer itself (the amount of RAM - I think). When enough
instances of this form are opened and the limit of the computer is reached
the program crashes and the user has to CTRL^ALT^DELETE and restart the
program.

Is there a way to detect when the computer is approaching its limit so that
I can prevent other instances of the form from being opened?

Also can anyone point me to some reading material on how to minimize the
amount of RAM used by MSACCESS MDE objects?

Thanks

G.Gerard
Jan 18 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

Jan 18 '06 #2

P: n/a
On Wed, 18 Jan 2006 01:10:05 GMT, "GGerard" <gg*****@nbnet.nb.ca>
wrote:

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

I have a program where the user can open as many instances of a form as the
user wants.

The only limit to how many instances can be opened is determined by the
limit of the computer itself (the amount of RAM - I think). When enough
instances of this form are opened and the limit of the computer is reached
the program crashes and the user has to CTRL^ALT^DELETE and restart the
program.

Is there a way to detect when the computer is approaching its limit so that
I can prevent other instances of the form from being opened?

Also can anyone point me to some reading material on how to minimize the
amount of RAM used by MSACCESS MDE objects?

Thanks

G.Gerard


Jan 18 '06 #3

P: n/a
"Pachydermitis" <pr*******@gmail.com> wrote in
news:11**********************@g44g2000cwa.googlegr oups.com:
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*.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Jan 18 '06 #4

P: n/a
On Wed, 18 Jan 2006 07:59:19 -0600, "David W. Fenton"
<XX*******@dfenton.com.invalid> wrote:

The writer was referring to two instances of the same *database*,
whereas you are referring to two instances of the same form.

-Tom.

"Pachydermitis" <pr*******@gmail.com> wrote in
news:11**********************@g44g2000cwa.googleg roups.com:
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*.


Jan 19 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.