Multiple Instances of a Form, ....one too many....

G

Gino

The automaion feature:
Like big companies do, when a phone call rings at the office, my Access
Database automatically opens a form displaying the caller information as
captured by the modem with caller ID (and searches the database to display
the customer record, if he is already in it).
If two or more calls come in while the user is not at his computer,
additional instances of the same form will open, with each form displaying
the info for each different caller.
I have been able to program Access to respond in the manner described above
by using some code I found on this forum plus the caller ID routine that came
with the Tapi ActiveX I am using.

The problem:
The problem I have is that whenever a phone call comes in, two instances of
the form get opened almost simultaneously instead of one.
If I put a break in the code and then proceed line by line with F8, then at
the end of the code, I find just one form (the code is written to generate
only one new instance of the form at each phone call). It almost looks as
if the computer runs too fast and generates a second form instance before the
next line of code is run...

Could it be due to the response of the Tapi ActiveX?
If so could I prevent it with some kind of timing loop?
Any suggestions?

Thank you very much!

_________________________________________________
Code to generate and manage multiple Form instances is here below.
Credit for code: 'Author: Allen J Browne, July 2004
_________________________________________________
Option Explicit
Public clnClient As New Collection 'Instances of frmClient.

Function OpenAClient()
'----Purpose: Open an independent instance of form frmCaller whenever a
new phone call comes in.

Dim frm As Form

'----Open a new instance, show it, and set a caption.
Set frm = New Form_frmCaller
frm.Visible = True
frm.Caption = frm.Hwnd & ", opened " & Format(Now(), "short time")

'----Append it to our collection.
clnClient.Add Item:=frm, Key:=CStr(frm.Hwnd)
'Set frm = Nothing

'--- Offset Position of new form on the screen (because new instance exactly
overlaps previous form

Dim lngKt As Long
Dim lngI As Long
Dim vrbPosition As Integer

lngKt = clnClient.Count
For lngI = 1 To lngKt
Next

vrbPosition = lngI * 500
frm.Move vrbPosition, vrbPosition

lngI = 1
Set frm = Nothing

End Function
_________________________________________________
 
E

ErezM via AccessMonster.com

hi
it does sound like some timing problem
one solution you might do is create a global variable, say you call it
blnWait As Boolean

in the procedure that creates the instances, first check if this variable is
true, and if it is, then exit the sub without doing anything

now, in your form blueprint (the form that's being opended multiple times),
set blnWait to True on the Open event, and then to False On the Timer event
now you'll need to play with the TimerInterval value until youll get the
desired Wait effect (the procedure will have to wait x miliseconds before
trying to open another form

hope this will help
good luck
Erez
 
G

Gino

Thank you very much Erez for taking the time to analyze the issue. I will try
your suggestion.
I have in the meantime come up with a temporary fix that seems to prevent
the double instance by inserting a msgbox that interrupts the code. After
clicking OK on the msgbox, the code runs to completion and at the end I find
only one instance of the form instead of two.

If the user is not at the computer however, the open msgbox would prevent
the program from responding to a subsequent phone call and so I use a:
SendKeys "{Enter}" , False
to push the "OK" button programmatically and run to completion after every
call.

I am now in the process of testing under different scenarios (like receiving
a call when another form in Access has the focus, or even being in a
different program like Internet explorer or photoshop) to see if I get
consistent behavior.

Thank you again for your assistance. I may post additional questions later
depending on these tests.
Gino
________________________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top