Discussion:
Caller ID in MS Access w/TAPI
(too old to reply)
YisMan
2007-09-03 19:46:00 UTC
Permalink
Hello everyone,

First thanks again to Grant Schenck and Matthias Moetje for their input on
my previous post, titled "Monitor Incoming Calls in MS Access". With their
guidance I progressed my code pretty much.

Now to the current problem. The code that I have now recognizes incoming
calls, but occasionally retrieves the Caller ID info, though most of the time
doesn't. The code is below. I'm working on this for weeks, but not making any
progress.

It seems to me that the problem is that the registration gets lost after the
call to the CallInfoObject.Call.CallInfoString method. thats why Iput a
"Register" call after each call to "CallInfoString". On the other hand my
googling tells me that all TAPI object must be completely destroyed between
each call to CallInfoString. So I'm torn balancing between destruction and
reregistration, which are pretty much two opposites, and have'nt found the
right mix yet.

Another oddity, which I'm not positive about, and is difficult to test for
sure. Sometimes when the TE_CALLINFOCHANGE is raised in debugging mode (due
to a breakpoint) then it actually DOES get Caller ID. As if it is a timing
problem.

The entire code is simply a class module which I call MCHTapi. I have one
more line of code, that is a global variable declared in a regular module as
such:
Public mTAPI As New MCHTapi

Here is the entire code as is. My greatest appreciation to all who are
taking the time to read this and respond to it.


Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768

Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address (you can
hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String

Dim MediaTypes As Long

'property let NewTAPI as TAPI3Lib.TAPI

'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property

'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property





Sub Setup()
'Reset
Initialize
Register
End Sub

Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent
As Object)
' If Not CallInfoObject Is Nothing Then Debug.Print
CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()

Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub


Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and ended calls
Debug.Print "CallNotificationEvent Type " & CallNotificationObject.Event & "
" & Time()
Select Case CallNotificationObject.Event

Case CNE_MONITOR
' the notification is for a monitored call
Debug.Print "Call Notification: CNE_MONITOR " & Time()
Case CNE_OWNER
' the notification is for an owned call
Debug.Print "Call Notification: CNE_OWNER " & Time()
End Select
Set CallNotificationObject = Nothing
End Sub

Private Sub CallStateEvent()
'Debug.Print "CallStateEvent Called " & Now()
' here we should check to see call state and handle connects and
disconnects
Select Case CallStateObject.State
Case CALL_STATE.CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CALL_STATE.CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CALL_STATE.CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
' a call is offering so if you dont want it then pass it
' the code to pass the call is the following
'Dim CallControl As ITBasicCallControl = CallStateObject.Call
'CallControl.HandoffIndirect
(CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
Case CALL_STATE.CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
' call is connected
Case CALL_STATE.CS_QUEUED
Debug.Print "Call State: CS_QUEUED " & Time()
' call is beeing queued
Case CALL_STATE.CS_HOLD
Debug.Print "Call State: CS_HOLD " & Time()
' call is on hold
Case CALL_STATE.CS_DISCONNECTED
CurrentCallerID = ""
Debug.Print "Call State: CS_DISCONNECTED " & Time()
'Register
' call is disconnected
End Select
Set CallStateObject = Nothing
End Sub

Private Sub CallInfoEvent()
Debug.Print "CallInfoEvent Called " & Time()
Dim CallerID As String
On Error Resume Next
CallerID = Nz(CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER), "")
On Error GoTo 0
Application.SysCmd acSysCmdSetStatus, "CID: " & CallerID

'Set CallInfoObject = Nothing
If CallerID = "" Or CallerID = CurrentCallerID Then GoTo Finish
Debug.Print "Last Caller: " & CurrentCallerID
CurrentCallerID = CallerID
'If CallerID = "" Then CallerID = "0527649971"
Debug.Print "Caller ID: "; CallerID
CallerID = Canonical(CallerID)
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' &
phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 & '|' &
fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then GoTo Finish
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
'ResetTapi


Finish:
Shutdown
Initialize
Register
End Sub

Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
Set CallNotificationObject = Nothing
Set CallStateObject = Nothing
Set CallInfoObject = Nothing
End Sub

Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
For Each Address In oTAPI.Addresses ' AddressCollection ' looping
through address collection
If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if
address is working
Dim MediaSupport As ITMediaSupport
Set MediaSupport = Address ' extracting meida support interface
from the address
MediaTypes = MediaSupport.MediaTypes ' extracting media types
supporting
Set MediaSupport = Nothing ' dispose of the object
If (MediaTypes And MediaModem) = MediaModem Then
If (MediaTypes And MediaAudio) = MediaAudio Then
Set oAddress = Address ' select this address
Exit For
End If
End If
End If
Next Address
If oAddress Is Nothing Then Exit Sub
Debug.Print "Registered at " & Time()
RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False,
MediaTypes, 1)
oTAPI.EventFilter = (1 Or 2 Or 4 Or 8 Or 16 Or 32 Or 64 Or 128 Or 256 Or
512 Or 1024 Or 2048 Or _
4096 Or 8192 Or 16384 Or 32768 Or 65536 Or 131072 Or 262144 Or
524288 Or 1048576 Or 2097152 Or 4194304 Or _
8388608 Or 16777216 Or 33554432)
End Sub

Sub Initialize()
Dim m_TAPI As New TAPI
m_TAPI.Initialize
Set oTAPI = m_TAPI
Set m_TAPI = Nothing
End Sub



Thankfully, YisMan
--Ever stop to think, and then forget to start again?
Grant Schenck
2007-09-04 14:21:45 UTC
Permalink
What does the TAPI Browser show? Does it reliably get caller ID for calls
where your app fails? If so you KNOW your app is at fault. If not then you
can be reasonably sure the TSP is failing somehow.
--
Grant Schenck
http://grantschenck.tripod.com/
Post by YisMan
Hello everyone,
First thanks again to Grant Schenck and Matthias Moetje for their input on
my previous post, titled "Monitor Incoming Calls in MS Access". With their
guidance I progressed my code pretty much.
Now to the current problem. The code that I have now recognizes incoming
calls, but occasionally retrieves the Caller ID info, though most of the time
doesn't. The code is below. I'm working on this for weeks, but not making any
progress.
It seems to me that the problem is that the registration gets lost after the
call to the CallInfoObject.Call.CallInfoString method. thats why Iput a
"Register" call after each call to "CallInfoString". On the other hand my
googling tells me that all TAPI object must be completely destroyed between
each call to CallInfoString. So I'm torn balancing between destruction and
reregistration, which are pretty much two opposites, and have'nt found the
right mix yet.
Another oddity, which I'm not positive about, and is difficult to test for
sure. Sometimes when the TE_CALLINFOCHANGE is raised in debugging mode (due
to a breakpoint) then it actually DOES get Caller ID. As if it is a timing
problem.
The entire code is simply a class module which I call MCHTapi. I have one
more line of code, that is a global variable declared in a regular module as
Public mTAPI As New MCHTapi
Here is the entire code as is. My greatest appreciation to all who are
taking the time to read this and respond to it.
Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address (you can
hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String
Dim MediaTypes As Long
'property let NewTAPI as TAPI3Lib.TAPI
'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property
'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property
Sub Setup()
'Reset
Initialize
Register
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent
As Object)
' If Not CallInfoObject Is Nothing Then Debug.Print
CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()
Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub
Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and ended calls
Debug.Print "CallNotificationEvent Type " & CallNotificationObject.Event & "
" & Time()
Select Case CallNotificationObject.Event
Case CNE_MONITOR
' the notification is for a monitored call
Debug.Print "Call Notification: CNE_MONITOR " & Time()
Case CNE_OWNER
' the notification is for an owned call
Debug.Print "Call Notification: CNE_OWNER " & Time()
End Select
Set CallNotificationObject = Nothing
End Sub
Private Sub CallStateEvent()
'Debug.Print "CallStateEvent Called " & Now()
' here we should check to see call state and handle connects and
disconnects
Select Case CallStateObject.State
Case CALL_STATE.CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CALL_STATE.CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CALL_STATE.CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
' a call is offering so if you dont want it then pass it
' the code to pass the call is the following
'Dim CallControl As ITBasicCallControl = CallStateObject.Call
'CallControl.HandoffIndirect
(CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
Case CALL_STATE.CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
' call is connected
Case CALL_STATE.CS_QUEUED
Debug.Print "Call State: CS_QUEUED " & Time()
' call is beeing queued
Case CALL_STATE.CS_HOLD
Debug.Print "Call State: CS_HOLD " & Time()
' call is on hold
Case CALL_STATE.CS_DISCONNECTED
CurrentCallerID = ""
Debug.Print "Call State: CS_DISCONNECTED " & Time()
'Register
' call is disconnected
End Select
Set CallStateObject = Nothing
End Sub
Private Sub CallInfoEvent()
Debug.Print "CallInfoEvent Called " & Time()
Dim CallerID As String
On Error Resume Next
CallerID = Nz(CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER), "")
On Error GoTo 0
Application.SysCmd acSysCmdSetStatus, "CID: " & CallerID
'Set CallInfoObject = Nothing
If CallerID = "" Or CallerID = CurrentCallerID Then GoTo Finish
Debug.Print "Last Caller: " & CurrentCallerID
CurrentCallerID = CallerID
'If CallerID = "" Then CallerID = "0527649971"
Debug.Print "Caller ID: "; CallerID
CallerID = Canonical(CallerID)
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' &
phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 & '|' &
fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then GoTo Finish
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
'ResetTapi
Shutdown
Initialize
Register
End Sub
Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
Set CallNotificationObject = Nothing
Set CallStateObject = Nothing
Set CallInfoObject = Nothing
End Sub
Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
For Each Address In oTAPI.Addresses ' AddressCollection ' looping
through address collection
If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if
address is working
Dim MediaSupport As ITMediaSupport
Set MediaSupport = Address ' extracting meida support interface
from the address
MediaTypes = MediaSupport.MediaTypes ' extracting media types
supporting
Set MediaSupport = Nothing ' dispose of the object
If (MediaTypes And MediaModem) = MediaModem Then
If (MediaTypes And MediaAudio) = MediaAudio Then
Set oAddress = Address ' select this address
Exit For
End If
End If
End If
Next Address
If oAddress Is Nothing Then Exit Sub
Debug.Print "Registered at " & Time()
RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False,
MediaTypes, 1)
oTAPI.EventFilter = (1 Or 2 Or 4 Or 8 Or 16 Or 32 Or 64 Or 128 Or 256 Or
512 Or 1024 Or 2048 Or _
4096 Or 8192 Or 16384 Or 32768 Or 65536 Or 131072 Or 262144 Or
524288 Or 1048576 Or 2097152 Or 4194304 Or _
8388608 Or 16777216 Or 33554432)
End Sub
Sub Initialize()
Dim m_TAPI As New TAPI
m_TAPI.Initialize
Set oTAPI = m_TAPI
Set m_TAPI = Nothing
End Sub
Thankfully, YisMan
--Ever stop to think, and then forget to start again?
YisMan
2007-09-04 14:54:03 UTC
Permalink
hi Grant,
Thanks again.

I did not check with the TAPI Browser, because I have the free version of
PhoneTray installed (http://www.phonetray.com), which shows the Caller ID no
problem each time, so I'm sure it's not my hardware or whatever. Neither will
the problem be by my telephone company.

So can we deduce that the problem is in the code?

One more point:
If you've glimpsed over my code, you might have realized a variable
"CurrentCallerID". The reason for this variable is because I reregister TAPI
after the CallInfoEvent. So then right away, after registration, the CallInfo
event fires again, which will again open the Person's Form. Hence, I'm
checking if this call is the same Caller ID as the last call. Of course this
is BAD. especially if that same fellow calls back 3 minutes later, his card
won't show up. I hope that this will also clear up, after we get this thing
working.

Thanks again for your input, I've been reading a lot of your TAPI posts
recently. They are very helpful and informative.

YisMan
Post by Grant Schenck
What does the TAPI Browser show? Does it reliably get caller ID for calls
where your app fails? If so you KNOW your app is at fault. If not then you
can be reasonably sure the TSP is failing somehow.
--
Grant Schenck
http://grantschenck.tripod.com/
Post by YisMan
Hello everyone,
First thanks again to Grant Schenck and Matthias Moetje for their input on
my previous post, titled "Monitor Incoming Calls in MS Access". With their
guidance I progressed my code pretty much.
Now to the current problem. The code that I have now recognizes incoming
calls, but occasionally retrieves the Caller ID info, though most of the time
doesn't. The code is below. I'm working on this for weeks, but not making any
progress.
It seems to me that the problem is that the registration gets lost after the
call to the CallInfoObject.Call.CallInfoString method. thats why Iput a
"Register" call after each call to "CallInfoString". On the other hand my
googling tells me that all TAPI object must be completely destroyed between
each call to CallInfoString. So I'm torn balancing between destruction and
reregistration, which are pretty much two opposites, and have'nt found the
right mix yet.
Another oddity, which I'm not positive about, and is difficult to test for
sure. Sometimes when the TE_CALLINFOCHANGE is raised in debugging mode (due
to a breakpoint) then it actually DOES get Caller ID. As if it is a timing
problem.
The entire code is simply a class module which I call MCHTapi. I have one
more line of code, that is a global variable declared in a regular module as
Public mTAPI As New MCHTapi
Here is the entire code as is. My greatest appreciation to all who are
taking the time to read this and respond to it.
Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address (you can
hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String
Dim MediaTypes As Long
'property let NewTAPI as TAPI3Lib.TAPI
'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property
'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property
Sub Setup()
'Reset
Initialize
Register
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent
As Object)
' If Not CallInfoObject Is Nothing Then Debug.Print
CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()
Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub
Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and ended calls
Debug.Print "CallNotificationEvent Type " & CallNotificationObject.Event & "
" & Time()
Select Case CallNotificationObject.Event
Case CNE_MONITOR
' the notification is for a monitored call
Debug.Print "Call Notification: CNE_MONITOR " & Time()
Case CNE_OWNER
' the notification is for an owned call
Debug.Print "Call Notification: CNE_OWNER " & Time()
End Select
Set CallNotificationObject = Nothing
End Sub
Private Sub CallStateEvent()
'Debug.Print "CallStateEvent Called " & Now()
' here we should check to see call state and handle connects and
disconnects
Select Case CallStateObject.State
Case CALL_STATE.CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CALL_STATE.CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CALL_STATE.CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
' a call is offering so if you dont want it then pass it
' the code to pass the call is the following
'Dim CallControl As ITBasicCallControl = CallStateObject.Call
'CallControl.HandoffIndirect
(CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
Case CALL_STATE.CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
' call is connected
Case CALL_STATE.CS_QUEUED
Debug.Print "Call State: CS_QUEUED " & Time()
' call is beeing queued
Case CALL_STATE.CS_HOLD
Debug.Print "Call State: CS_HOLD " & Time()
' call is on hold
Case CALL_STATE.CS_DISCONNECTED
CurrentCallerID = ""
Debug.Print "Call State: CS_DISCONNECTED " & Time()
'Register
' call is disconnected
End Select
Set CallStateObject = Nothing
End Sub
Private Sub CallInfoEvent()
Debug.Print "CallInfoEvent Called " & Time()
Dim CallerID As String
On Error Resume Next
CallerID = Nz(CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER), "")
On Error GoTo 0
Application.SysCmd acSysCmdSetStatus, "CID: " & CallerID
'Set CallInfoObject = Nothing
If CallerID = "" Or CallerID = CurrentCallerID Then GoTo Finish
Debug.Print "Last Caller: " & CurrentCallerID
CurrentCallerID = CallerID
'If CallerID = "" Then CallerID = "0527649971"
Debug.Print "Caller ID: "; CallerID
CallerID = Canonical(CallerID)
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' &
phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 & '|' &
fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then GoTo Finish
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
'ResetTapi
Shutdown
Initialize
Register
End Sub
Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
Set CallNotificationObject = Nothing
Set CallStateObject = Nothing
Set CallInfoObject = Nothing
End Sub
Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
For Each Address In oTAPI.Addresses ' AddressCollection ' looping
through address collection
If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if
address is working
Dim MediaSupport As ITMediaSupport
Set MediaSupport = Address ' extracting meida support interface
from the address
MediaTypes = MediaSupport.MediaTypes ' extracting media types
supporting
Set MediaSupport = Nothing ' dispose of the object
If (MediaTypes And MediaModem) = MediaModem Then
If (MediaTypes And MediaAudio) = MediaAudio Then
Set oAddress = Address ' select this address
Exit For
End If
End If
End If
Next Address
If oAddress Is Nothing Then Exit Sub
Debug.Print "Registered at " & Time()
RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False,
MediaTypes, 1)
oTAPI.EventFilter = (1 Or 2 Or 4 Or 8 Or 16 Or 32 Or 64 Or 128 Or 256 Or
512 Or 1024 Or 2048 Or _
4096 Or 8192 Or 16384 Or 32768 Or 65536 Or 131072 Or 262144 Or
524288 Or 1048576 Or 2097152 Or 4194304 Or _
8388608 Or 16777216 Or 33554432)
End Sub
Sub Initialize()
Dim m_TAPI As New TAPI
m_TAPI.Initialize
Set oTAPI = m_TAPI
Set m_TAPI = Nothing
End Sub
Thankfully, YisMan
--Ever stop to think, and then forget to start again?
Grant Schenck
2007-09-04 18:38:59 UTC
Permalink
I'm not particularly good with TAPI 3.x so perhaps someone else who is can
chime in. That said, coming from TAPI 2.x, the BEST way to understand TAPI
and how to use it correctly is to walk though a scenario using the TAPI
Browser. Until you are willing to invest the time to learn that you really
can't expect to make much progress.
--
Grant Schenck
http://grantschenck.tripod.com/
Post by YisMan
hi Grant,
Thanks again.
I did not check with the TAPI Browser, because I have the free version of
PhoneTray installed (http://www.phonetray.com), which shows the Caller ID no
problem each time, so I'm sure it's not my hardware or whatever. Neither will
the problem be by my telephone company.
So can we deduce that the problem is in the code?
If you've glimpsed over my code, you might have realized a variable
"CurrentCallerID". The reason for this variable is because I reregister TAPI
after the CallInfoEvent. So then right away, after registration, the CallInfo
event fires again, which will again open the Person's Form. Hence, I'm
checking if this call is the same Caller ID as the last call. Of course this
is BAD. especially if that same fellow calls back 3 minutes later, his card
won't show up. I hope that this will also clear up, after we get this thing
working.
Thanks again for your input, I've been reading a lot of your TAPI posts
recently. They are very helpful and informative.
YisMan
Post by Grant Schenck
What does the TAPI Browser show? Does it reliably get caller ID for calls
where your app fails? If so you KNOW your app is at fault. If not then you
can be reasonably sure the TSP is failing somehow.
--
Grant Schenck
http://grantschenck.tripod.com/
Post by YisMan
Hello everyone,
First thanks again to Grant Schenck and Matthias Moetje for their input on
my previous post, titled "Monitor Incoming Calls in MS Access". With their
guidance I progressed my code pretty much.
Now to the current problem. The code that I have now recognizes incoming
calls, but occasionally retrieves the Caller ID info, though most of
the
time
doesn't. The code is below. I'm working on this for weeks, but not
making
any
progress.
It seems to me that the problem is that the registration gets lost
after
the
call to the CallInfoObject.Call.CallInfoString method. thats why Iput a
"Register" call after each call to "CallInfoString". On the other hand my
googling tells me that all TAPI object must be completely destroyed between
each call to CallInfoString. So I'm torn balancing between destruction and
reregistration, which are pretty much two opposites, and have'nt found the
right mix yet.
Another oddity, which I'm not positive about, and is difficult to test for
sure. Sometimes when the TE_CALLINFOCHANGE is raised in debugging mode (due
to a breakpoint) then it actually DOES get Caller ID. As if it is a timing
problem.
The entire code is simply a class module which I call MCHTapi. I have one
more line of code, that is a global variable declared in a regular
module
as
Public mTAPI As New MCHTapi
Here is the entire code as is. My greatest appreciation to all who are
taking the time to read this and respond to it.
Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address (you can
hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String
Dim MediaTypes As Long
'property let NewTAPI as TAPI3Lib.TAPI
'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property
'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property
Sub Setup()
'Reset
Initialize
Register
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent
As Object)
' If Not CallInfoObject Is Nothing Then Debug.Print
CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()
Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub
Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and ended calls
Debug.Print "CallNotificationEvent Type " &
CallNotificationObject.Event &
"
" & Time()
Select Case CallNotificationObject.Event
Case CNE_MONITOR
' the notification is for a monitored call
Debug.Print "Call Notification: CNE_MONITOR " & Time()
Case CNE_OWNER
' the notification is for an owned call
Debug.Print "Call Notification: CNE_OWNER " & Time()
End Select
Set CallNotificationObject = Nothing
End Sub
Private Sub CallStateEvent()
'Debug.Print "CallStateEvent Called " & Now()
' here we should check to see call state and handle connects and
disconnects
Select Case CallStateObject.State
Case CALL_STATE.CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CALL_STATE.CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CALL_STATE.CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
' a call is offering so if you dont want it then pass it
' the code to pass the call is the following
'Dim CallControl As ITBasicCallControl = CallStateObject.Call
'CallControl.HandoffIndirect
(CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
Case CALL_STATE.CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
' call is connected
Case CALL_STATE.CS_QUEUED
Debug.Print "Call State: CS_QUEUED " & Time()
' call is beeing queued
Case CALL_STATE.CS_HOLD
Debug.Print "Call State: CS_HOLD " & Time()
' call is on hold
Case CALL_STATE.CS_DISCONNECTED
CurrentCallerID = ""
Debug.Print "Call State: CS_DISCONNECTED " & Time()
'Register
' call is disconnected
End Select
Set CallStateObject = Nothing
End Sub
Private Sub CallInfoEvent()
Debug.Print "CallInfoEvent Called " & Time()
Dim CallerID As String
On Error Resume Next
CallerID =
Nz(CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER),
"")
On Error GoTo 0
Application.SysCmd acSysCmdSetStatus, "CID: " & CallerID
'Set CallInfoObject = Nothing
If CallerID = "" Or CallerID = CurrentCallerID Then GoTo Finish
Debug.Print "Last Caller: " & CurrentCallerID
CurrentCallerID = CallerID
'If CallerID = "" Then CallerID = "0527649971"
Debug.Print "Caller ID: "; CallerID
CallerID = Canonical(CallerID)
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' &
phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 &
'|'
&
fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then GoTo Finish
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
'ResetTapi
Shutdown
Initialize
Register
End Sub
Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
Set CallNotificationObject = Nothing
Set CallStateObject = Nothing
Set CallInfoObject = Nothing
End Sub
Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
For Each Address In oTAPI.Addresses ' AddressCollection ' looping
through address collection
If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if
address is working
Dim MediaSupport As ITMediaSupport
Set MediaSupport = Address ' extracting meida support interface
from the address
MediaTypes = MediaSupport.MediaTypes ' extracting media types
supporting
Set MediaSupport = Nothing ' dispose of the object
If (MediaTypes And MediaModem) = MediaModem Then
If (MediaTypes And MediaAudio) = MediaAudio Then
Set oAddress = Address ' select this address
Exit For
End If
End If
End If
Next Address
If oAddress Is Nothing Then Exit Sub
Debug.Print "Registered at " & Time()
RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False,
MediaTypes, 1)
oTAPI.EventFilter = (1 Or 2 Or 4 Or 8 Or 16 Or 32 Or 64 Or 128 Or
256
Or
512 Or 1024 Or 2048 Or _
4096 Or 8192 Or 16384 Or 32768 Or 65536 Or 131072 Or 262144 Or
524288 Or 1048576 Or 2097152 Or 4194304 Or _
8388608 Or 16777216 Or 33554432)
End Sub
Sub Initialize()
Dim m_TAPI As New TAPI
m_TAPI.Initialize
Set oTAPI = m_TAPI
Set m_TAPI = Nothing
End Sub
Thankfully, YisMan
--Ever stop to think, and then forget to start again?
Matthias Moetje [MVP]
2007-09-05 21:41:27 UTC
Permalink
Yisman,

here are some essential tips for TAPI3:

---------------------------------------------------------------------

You MUST NOT store the event objects which you receive with TAPI
events:
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent

These objects are valid only within the event procecure and are reused
by TAPI. If you store the object pointers, TAPI cannot reuse them and
will stop firing events.

---------------------------------------------------------------------

You MUST handle errors when calling the ::CallInfoxxx methods.
When you use "On Error Resume Next", you must do

If Err Then Err.Clear

Or you create a normal event handler and call either "Err.Clear", "Resume"
or "Resume Next" or "Resume <Label>" after processing the error.


---------------------------------------------------------------------

Regarding the CallerID availability I guess the information is not available
after the first ring but just with the second ring (in analog networks the
CallerID is transmitted between the first and the second ring). Since you
store the ITCallNotificationEvent object, TAPI can't fire it a second time
when the information becomes available.


Best regards,

Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Hello everyone,
First thanks again to Grant Schenck and Matthias Moetje for their input on
my previous post, titled "Monitor Incoming Calls in MS Access". With their
guidance I progressed my code pretty much.
Now to the current problem. The code that I have now recognizes incoming
calls, but occasionally retrieves the Caller ID info, though most of the time
doesn't. The code is below. I'm working on this for weeks, but not making any
progress.
It seems to me that the problem is that the registration gets lost after the
call to the CallInfoObject.Call.CallInfoString method. thats why Iput a
"Register" call after each call to "CallInfoString". On the other hand my
googling tells me that all TAPI object must be completely destroyed between
each call to CallInfoString. So I'm torn balancing between destruction and
reregistration, which are pretty much two opposites, and have'nt found the
right mix yet.
Another oddity, which I'm not positive about, and is difficult to test for
sure. Sometimes when the TE_CALLINFOCHANGE is raised in debugging mode (due
to a breakpoint) then it actually DOES get Caller ID. As if it is a timing
problem.
The entire code is simply a class module which I call MCHTapi. I have one
more line of code, that is a global variable declared in a regular module as
Public mTAPI As New MCHTapi
Here is the entire code as is. My greatest appreciation to all who are
taking the time to read this and respond to it.
Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address (you can
hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String
Dim MediaTypes As Long
'property let NewTAPI as TAPI3Lib.TAPI
'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property
'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property
Sub Setup()
'Reset
Initialize
Register
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent
As Object)
' If Not CallInfoObject Is Nothing Then Debug.Print
CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()
Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub
Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and ended calls
Debug.Print "CallNotificationEvent Type " & CallNotificationObject.Event & "
" & Time()
Select Case CallNotificationObject.Event
Case CNE_MONITOR
' the notification is for a monitored call
Debug.Print "Call Notification: CNE_MONITOR " & Time()
Case CNE_OWNER
' the notification is for an owned call
Debug.Print "Call Notification: CNE_OWNER " & Time()
End Select
Set CallNotificationObject = Nothing
End Sub
Private Sub CallStateEvent()
'Debug.Print "CallStateEvent Called " & Now()
' here we should check to see call state and handle connects and
disconnects
Select Case CallStateObject.State
Case CALL_STATE.CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CALL_STATE.CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CALL_STATE.CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
' a call is offering so if you dont want it then pass it
' the code to pass the call is the following
'Dim CallControl As ITBasicCallControl = CallStateObject.Call
'CallControl.HandoffIndirect
(CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
Case CALL_STATE.CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
' call is connected
Case CALL_STATE.CS_QUEUED
Debug.Print "Call State: CS_QUEUED " & Time()
' call is beeing queued
Case CALL_STATE.CS_HOLD
Debug.Print "Call State: CS_HOLD " & Time()
' call is on hold
Case CALL_STATE.CS_DISCONNECTED
CurrentCallerID = ""
Debug.Print "Call State: CS_DISCONNECTED " & Time()
'Register
' call is disconnected
End Select
Set CallStateObject = Nothing
End Sub
Private Sub CallInfoEvent()
Debug.Print "CallInfoEvent Called " & Time()
Dim CallerID As String
On Error Resume Next
CallerID = Nz(CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER), "")
On Error GoTo 0
Application.SysCmd acSysCmdSetStatus, "CID: " & CallerID
'Set CallInfoObject = Nothing
If CallerID = "" Or CallerID = CurrentCallerID Then GoTo Finish
Debug.Print "Last Caller: " & CurrentCallerID
CurrentCallerID = CallerID
'If CallerID = "" Then CallerID = "0527649971"
Debug.Print "Caller ID: "; CallerID
CallerID = Canonical(CallerID)
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' &
phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 & '|' &
fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then GoTo Finish
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
'ResetTapi
Shutdown
Initialize
Register
End Sub
Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
Set CallNotificationObject = Nothing
Set CallStateObject = Nothing
Set CallInfoObject = Nothing
End Sub
Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
For Each Address In oTAPI.Addresses ' AddressCollection ' looping
through address collection
If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if
address is working
Dim MediaSupport As ITMediaSupport
Set MediaSupport = Address ' extracting meida support interface
from the address
MediaTypes = MediaSupport.MediaTypes ' extracting media types
supporting
Set MediaSupport = Nothing ' dispose of the object
If (MediaTypes And MediaModem) = MediaModem Then
If (MediaTypes And MediaAudio) = MediaAudio Then
Set oAddress = Address ' select this address
Exit For
End If
End If
End If
Next Address
If oAddress Is Nothing Then Exit Sub
Debug.Print "Registered at " & Time()
RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False,
MediaTypes, 1)
oTAPI.EventFilter = (1 Or 2 Or 4 Or 8 Or 16 Or 32 Or 64 Or 128 Or 256 Or
512 Or 1024 Or 2048 Or _
4096 Or 8192 Or 16384 Or 32768 Or 65536 Or 131072 Or 262144 Or
524288 Or 1048576 Or 2097152 Or 4194304 Or _
8388608 Or 16777216 Or 33554432)
End Sub
Sub Initialize()
Dim m_TAPI As New TAPI
m_TAPI.Initialize
Set oTAPI = m_TAPI
Set m_TAPI = Nothing
End Sub
Thankfully, YisMan
--Ever stop to think, and then forget to start again?
YisMan
2007-09-06 06:22:02 UTC
Permalink
Thanks Matthias,

I was really hoping you'd join in. These are golden bits of info. Only much
later today will I have time to analyze it against my code. I will then let
you know what's going.

Your help is truly appreciated.
Thankfully,
YisMan
Post by Matthias Moetje [MVP]
Yisman,
---------------------------------------------------------------------
You MUST NOT store the event objects which you receive with TAPI
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
These objects are valid only within the event procecure and are reused
by TAPI. If you store the object pointers, TAPI cannot reuse them and
will stop firing events.
---------------------------------------------------------------------
You MUST handle errors when calling the ::CallInfoxxx methods.
When you use "On Error Resume Next", you must do
If Err Then Err.Clear
Or you create a normal event handler and call either "Err.Clear", "Resume"
or "Resume Next" or "Resume <Label>" after processing the error.
---------------------------------------------------------------------
Regarding the CallerID availability I guess the information is not available
after the first ring but just with the second ring (in analog networks the
CallerID is transmitted between the first and the second ring). Since you
store the ITCallNotificationEvent object, TAPI can't fire it a second time
when the information becomes available.
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Hello everyone,
First thanks again to Grant Schenck and Matthias Moetje for their input on
my previous post, titled "Monitor Incoming Calls in MS Access". With their
guidance I progressed my code pretty much.
Now to the current problem. The code that I have now recognizes incoming
calls, but occasionally retrieves the Caller ID info, though most of the time
doesn't. The code is below. I'm working on this for weeks, but not making any
progress.
It seems to me that the problem is that the registration gets lost after the
call to the CallInfoObject.Call.CallInfoString method. thats why Iput a
"Register" call after each call to "CallInfoString". On the other hand my
googling tells me that all TAPI object must be completely destroyed between
each call to CallInfoString. So I'm torn balancing between destruction and
reregistration, which are pretty much two opposites, and have'nt found the
right mix yet.
Another oddity, which I'm not positive about, and is difficult to test for
sure. Sometimes when the TE_CALLINFOCHANGE is raised in debugging mode (due
to a breakpoint) then it actually DOES get Caller ID. As if it is a timing
problem.
The entire code is simply a class module which I call MCHTapi. I have one
more line of code, that is a global variable declared in a regular module as
Public mTAPI As New MCHTapi
Here is the entire code as is. My greatest appreciation to all who are
taking the time to read this and respond to it.
Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address (you can
hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String
Dim MediaTypes As Long
'property let NewTAPI as TAPI3Lib.TAPI
'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property
'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property
Sub Setup()
'Reset
Initialize
Register
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent
As Object)
' If Not CallInfoObject Is Nothing Then Debug.Print
CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()
Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub
Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and ended calls
Debug.Print "CallNotificationEvent Type " & CallNotificationObject.Event & "
" & Time()
Select Case CallNotificationObject.Event
Case CNE_MONITOR
' the notification is for a monitored call
Debug.Print "Call Notification: CNE_MONITOR " & Time()
Case CNE_OWNER
' the notification is for an owned call
Debug.Print "Call Notification: CNE_OWNER " & Time()
End Select
Set CallNotificationObject = Nothing
End Sub
Private Sub CallStateEvent()
'Debug.Print "CallStateEvent Called " & Now()
' here we should check to see call state and handle connects and
disconnects
Select Case CallStateObject.State
Case CALL_STATE.CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CALL_STATE.CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CALL_STATE.CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
' a call is offering so if you dont want it then pass it
' the code to pass the call is the following
'Dim CallControl As ITBasicCallControl = CallStateObject.Call
'CallControl.HandoffIndirect
(CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
Case CALL_STATE.CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
' call is connected
Case CALL_STATE.CS_QUEUED
Debug.Print "Call State: CS_QUEUED " & Time()
' call is beeing queued
Case CALL_STATE.CS_HOLD
Debug.Print "Call State: CS_HOLD " & Time()
' call is on hold
Case CALL_STATE.CS_DISCONNECTED
CurrentCallerID = ""
Debug.Print "Call State: CS_DISCONNECTED " & Time()
'Register
' call is disconnected
End Select
Set CallStateObject = Nothing
End Sub
Private Sub CallInfoEvent()
Debug.Print "CallInfoEvent Called " & Time()
Dim CallerID As String
On Error Resume Next
CallerID = Nz(CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER), "")
On Error GoTo 0
Application.SysCmd acSysCmdSetStatus, "CID: " & CallerID
'Set CallInfoObject = Nothing
If CallerID = "" Or CallerID = CurrentCallerID Then GoTo Finish
Debug.Print "Last Caller: " & CurrentCallerID
CurrentCallerID = CallerID
'If CallerID = "" Then CallerID = "0527649971"
Debug.Print "Caller ID: "; CallerID
CallerID = Canonical(CallerID)
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' &
phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 & '|' &
fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then GoTo Finish
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
'ResetTapi
Shutdown
Initialize
Register
End Sub
Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
Set CallNotificationObject = Nothing
Set CallStateObject = Nothing
Set CallInfoObject = Nothing
End Sub
Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
Matthias Moetje [MVP]
2007-09-06 18:19:37 UTC
Permalink
YisMan,
Post by YisMan
Your help is truly appreciated.
Thankfully,
Thanks for your feedback, you're welcome!


Best regards,

Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Post by Matthias Moetje [MVP]
---------------------------------------------------------------------
You MUST NOT store the event objects which you receive with TAPI
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
These objects are valid only within the event procecure and are reused
by TAPI. If you store the object pointers, TAPI cannot reuse them and
will stop firing events.
---------------------------------------------------------------------
You MUST handle errors when calling the ::CallInfoxxx methods.
When you use "On Error Resume Next", you must do
If Err Then Err.Clear
Or you create a normal event handler and call either "Err.Clear", "Resume"
or "Resume Next" or "Resume <Label>" after processing the error.
---------------------------------------------------------------------
Regarding the CallerID availability I guess the information is not available
after the first ring but just with the second ring (in analog networks the
CallerID is transmitted between the first and the second ring). Since you
store the ITCallNotificationEvent object, TAPI can't fire it a second time
when the information becomes available.
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Hello everyone,
First thanks again to Grant Schenck and Matthias Moetje for their input on
my previous post, titled "Monitor Incoming Calls in MS Access". With their
guidance I progressed my code pretty much.
Now to the current problem. The code that I have now recognizes incoming
calls, but occasionally retrieves the Caller ID info, though most of
the
time
doesn't. The code is below. I'm working on this for weeks, but not
making
any
progress.
It seems to me that the problem is that the registration gets lost
after
the
call to the CallInfoObject.Call.CallInfoString method. thats why Iput a
"Register" call after each call to "CallInfoString". On the other hand my
googling tells me that all TAPI object must be completely destroyed between
each call to CallInfoString. So I'm torn balancing between destruction and
reregistration, which are pretty much two opposites, and have'nt found the
right mix yet.
Another oddity, which I'm not positive about, and is difficult to test for
sure. Sometimes when the TE_CALLINFOCHANGE is raised in debugging mode (due
to a breakpoint) then it actually DOES get Caller ID. As if it is a timing
problem.
The entire code is simply a class module which I call MCHTapi. I have one
more line of code, that is a global variable declared in a regular
module
as
Public mTAPI As New MCHTapi
Here is the entire code as is. My greatest appreciation to all who are
taking the time to read this and respond to it.
Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address (you can
hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String
Dim MediaTypes As Long
'property let NewTAPI as TAPI3Lib.TAPI
'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property
'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property
Sub Setup()
'Reset
Initialize
Register
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent
As Object)
' If Not CallInfoObject Is Nothing Then Debug.Print
CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()
Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub
Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and ended calls
Debug.Print "CallNotificationEvent Type " &
CallNotificationObject.Event &
"
" & Time()
Select Case CallNotificationObject.Event
Case CNE_MONITOR
' the notification is for a monitored call
Debug.Print "Call Notification: CNE_MONITOR " & Time()
Case CNE_OWNER
' the notification is for an owned call
Debug.Print "Call Notification: CNE_OWNER " & Time()
End Select
Set CallNotificationObject = Nothing
End Sub
Private Sub CallStateEvent()
'Debug.Print "CallStateEvent Called " & Now()
' here we should check to see call state and handle connects and
disconnects
Select Case CallStateObject.State
Case CALL_STATE.CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CALL_STATE.CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CALL_STATE.CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
' a call is offering so if you dont want it then pass it
' the code to pass the call is the following
'Dim CallControl As ITBasicCallControl = CallStateObject.Call
'CallControl.HandoffIndirect
(CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
Case CALL_STATE.CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
' call is connected
Case CALL_STATE.CS_QUEUED
Debug.Print "Call State: CS_QUEUED " & Time()
' call is beeing queued
Case CALL_STATE.CS_HOLD
Debug.Print "Call State: CS_HOLD " & Time()
' call is on hold
Case CALL_STATE.CS_DISCONNECTED
CurrentCallerID = ""
Debug.Print "Call State: CS_DISCONNECTED " & Time()
'Register
' call is disconnected
End Select
Set CallStateObject = Nothing
End Sub
Private Sub CallInfoEvent()
Debug.Print "CallInfoEvent Called " & Time()
Dim CallerID As String
On Error Resume Next
CallerID =
Nz(CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER),
"")
On Error GoTo 0
Application.SysCmd acSysCmdSetStatus, "CID: " & CallerID
'Set CallInfoObject = Nothing
If CallerID = "" Or CallerID = CurrentCallerID Then GoTo Finish
Debug.Print "Last Caller: " & CurrentCallerID
CurrentCallerID = CallerID
'If CallerID = "" Then CallerID = "0527649971"
Debug.Print "Caller ID: "; CallerID
CallerID = Canonical(CallerID)
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' &
phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 &
'|'
&
fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then GoTo Finish
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
'ResetTapi
Shutdown
Initialize
Register
End Sub
Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
Set CallNotificationObject = Nothing
Set CallStateObject = Nothing
Set CallInfoObject = Nothing
End Sub
Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
YisMan
2007-09-07 08:08:03 UTC
Permalink
Okay, Matthias. Thanks. Been there, done that.

I overhauled my code (i'll post it in a minute), there are now no stored
variables save for the main oTAPI object WithEvents and the RegCookie integer.

Additionally I have added an error handler for the entire oTAPI_Event
method. I Also generally cleaned up and tidied up the entire MCHTapi module,
all in your merit. This has its own big benefits! <g>

What is happening now is that when i first open my access app, the CID
catches and everything is great, thank you. after that, any other calls
coming in it does not work. only the address, callhub, and callstate events
are called. the CallInfoChange event is not called.
If I close the program and reopen after a few minutes, it'll work one more
time.
The additional calls sometime raises the err handler

ITS WORKING!!!!!!!!!!!!!!!

in middle of writing this reply, i insrted a for-next line as a delayer
before the resume next, and its just plain WORKING!!!!!!! Thanks Matthias,
you've done it again!
if someone calls maybe the exact millisecond after the other, it doesnt
catch but otherwise it just plain works!!

I'm so happy! i'm working on this for two months! God is good!
Don't you always put your phone number in your posts? I want to call you to
thank you.

I'm out of words. I almost gave up already.

May God bless you with long life and all blessings!
--
Thankfully, YisMan
Post by Matthias Moetje [MVP]
YisMan,
Post by YisMan
Your help is truly appreciated.
Thankfully,
Thanks for your feedback, you're welcome!
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Post by Matthias Moetje [MVP]
---------------------------------------------------------------------
You MUST NOT store the event objects which you receive with TAPI
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
These objects are valid only within the event procecure and are reused
by TAPI. If you store the object pointers, TAPI cannot reuse them and
will stop firing events.
---------------------------------------------------------------------
You MUST handle errors when calling the ::CallInfoxxx methods.
When you use "On Error Resume Next", you must do
If Err Then Err.Clear
Or you create a normal event handler and call either "Err.Clear", "Resume"
or "Resume Next" or "Resume <Label>" after processing the error.
---------------------------------------------------------------------
Regarding the CallerID availability I guess the information is not available
after the first ring but just with the second ring (in analog networks the
CallerID is transmitted between the first and the second ring). Since you
store the ITCallNotificationEvent object, TAPI can't fire it a second time
when the information becomes available.
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Hello everyone,
First thanks again to Grant Schenck and Matthias Moetje for their input on
my previous post, titled "Monitor Incoming Calls in MS Access". With their
guidance I progressed my code pretty much.
Now to the current problem. The code that I have now recognizes incoming
calls, but occasionally retrieves the Caller ID info, though most of
the
time
doesn't. The code is below. I'm working on this for weeks, but not
making
any
progress.
It seems to me that the problem is that the registration gets lost
after
the
call to the CallInfoObject.Call.CallInfoString method. thats why Iput a
"Register" call after each call to "CallInfoString". On the other hand my
googling tells me that all TAPI object must be completely destroyed between
each call to CallInfoString. So I'm torn balancing between destruction and
reregistration, which are pretty much two opposites, and have'nt found the
right mix yet.
Another oddity, which I'm not positive about, and is difficult to test for
sure. Sometimes when the TE_CALLINFOCHANGE is raised in debugging mode (due
to a breakpoint) then it actually DOES get Caller ID. As if it is a timing
problem.
The entire code is simply a class module which I call MCHTapi. I have one
more line of code, that is a global variable declared in a regular
module
as
Public mTAPI As New MCHTapi
Here is the entire code as is. My greatest appreciation to all who are
taking the time to read this and respond to it.
Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address (you can
hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String
Dim MediaTypes As Long
'property let NewTAPI as TAPI3Lib.TAPI
'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property
'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property
Sub Setup()
'Reset
Initialize
Register
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent
As Object)
' If Not CallInfoObject Is Nothing Then Debug.Print
CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()
Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub
Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and ended calls
Debug.Print "CallNotificationEvent Type " &
CallNotificationObject.Event &
"
" & Time()
Select Case CallNotificationObject.Event
Case CNE_MONITOR
' the notification is for a monitored call
Debug.Print "Call Notification: CNE_MONITOR " & Time()
Case CNE_OWNER
' the notification is for an owned call
Debug.Print "Call Notification: CNE_OWNER " & Time()
End Select
Set CallNotificationObject = Nothing
End Sub
Private Sub CallStateEvent()
'Debug.Print "CallStateEvent Called " & Now()
' here we should check to see call state and handle connects and
disconnects
Select Case CallStateObject.State
Case CALL_STATE.CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CALL_STATE.CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CALL_STATE.CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
' a call is offering so if you dont want it then pass it
' the code to pass the call is the following
'Dim CallControl As ITBasicCallControl = CallStateObject.Call
'CallControl.HandoffIndirect
(CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
Case CALL_STATE.CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
' call is connected
Case CALL_STATE.CS_QUEUED
Debug.Print "Call State: CS_QUEUED " & Time()
' call is beeing queued
Case CALL_STATE.CS_HOLD
Debug.Print "Call State: CS_HOLD " & Time()
' call is on hold
Case CALL_STATE.CS_DISCONNECTED
CurrentCallerID = ""
Debug.Print "Call State: CS_DISCONNECTED " & Time()
'Register
' call is disconnected
End Select
Set CallStateObject = Nothing
End Sub
Private Sub CallInfoEvent()
Debug.Print "CallInfoEvent Called " & Time()
Dim CallerID As String
Matthias Moetje [MVP]
2007-09-07 12:56:05 UTC
Permalink
YisMan,

I am not sure why you would need a delay, and can't say without seeing your
code, but I'm glad to hear that it's at least working now!
Post by YisMan
I'm so happy! i'm working on this for two months! God is good!
Don't you always put your phone number in your posts? I want to call you to
thank you.
I'm out of words. I almost gave up already.
May God bless you with long life and all blessings!
Always glad to help! You're welcome!

Best regards,

Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Post by Matthias Moetje [MVP]
YisMan,
Post by YisMan
Your help is truly appreciated.
Thankfully,
Thanks for your feedback, you're welcome!
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Post by Matthias Moetje [MVP]
---------------------------------------------------------------------
You MUST NOT store the event objects which you receive with TAPI
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
These objects are valid only within the event procecure and are reused
by TAPI. If you store the object pointers, TAPI cannot reuse them and
will stop firing events.
---------------------------------------------------------------------
You MUST handle errors when calling the ::CallInfoxxx methods.
When you use "On Error Resume Next", you must do
If Err Then Err.Clear
Or you create a normal event handler and call either "Err.Clear", "Resume"
or "Resume Next" or "Resume <Label>" after processing the error.
---------------------------------------------------------------------
Regarding the CallerID availability I guess the information is not available
after the first ring but just with the second ring (in analog networks the
CallerID is transmitted between the first and the second ring). Since you
store the ITCallNotificationEvent object, TAPI can't fire it a second time
when the information becomes available.
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Hello everyone,
First thanks again to Grant Schenck and Matthias Moetje for their
input
on
my previous post, titled "Monitor Incoming Calls in MS Access". With their
guidance I progressed my code pretty much.
Now to the current problem. The code that I have now recognizes incoming
calls, but occasionally retrieves the Caller ID info, though most of
the
time
doesn't. The code is below. I'm working on this for weeks, but not
making
any
progress.
It seems to me that the problem is that the registration gets lost
after
the
call to the CallInfoObject.Call.CallInfoString method. thats why Iput a
"Register" call after each call to "CallInfoString". On the other
hand
my
googling tells me that all TAPI object must be completely destroyed between
each call to CallInfoString. So I'm torn balancing between
destruction
and
reregistration, which are pretty much two opposites, and have'nt
found
the
right mix yet.
Another oddity, which I'm not positive about, and is difficult to
test
for
sure. Sometimes when the TE_CALLINFOCHANGE is raised in debugging
mode
(due
to a breakpoint) then it actually DOES get Caller ID. As if it is a timing
problem.
The entire code is simply a class module which I call MCHTapi. I
have
one
more line of code, that is a global variable declared in a regular
module
as
Public mTAPI As New MCHTapi
Here is the entire code as is. My greatest appreciation to all who are
taking the time to read this and respond to it.
Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address (you can
hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String
Dim MediaTypes As Long
'property let NewTAPI as TAPI3Lib.TAPI
'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property
'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property
Sub Setup()
'Reset
Initialize
Register
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT,
ByVal
pEvent
As Object)
' If Not CallInfoObject Is Nothing Then Debug.Print
CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()
Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub
Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and ended calls
Debug.Print "CallNotificationEvent Type " &
CallNotificationObject.Event &
"
" & Time()
Select Case CallNotificationObject.Event
Case CNE_MONITOR
' the notification is for a monitored call
Debug.Print "Call Notification: CNE_MONITOR " & Time()
Case CNE_OWNER
' the notification is for an owned call
Debug.Print "Call Notification: CNE_OWNER " & Time()
End Select
Set CallNotificationObject = Nothing
End Sub
Private Sub CallStateEvent()
'Debug.Print "CallStateEvent Called " & Now()
' here we should check to see call state and handle connects and
disconnects
Select Case CallStateObject.State
Case CALL_STATE.CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CALL_STATE.CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CALL_STATE.CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
' a call is offering so if you dont want it then pass it
' the code to pass the call is the following
'Dim CallControl As ITBasicCallControl = CallStateObject.Call
'CallControl.HandoffIndirect
(CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
Case CALL_STATE.CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
' call is connected
Case CALL_STATE.CS_QUEUED
Debug.Print "Call State: CS_QUEUED " & Time()
' call is beeing queued
Case CALL_STATE.CS_HOLD
Debug.Print "Call State: CS_HOLD " & Time()
' call is on hold
Case CALL_STATE.CS_DISCONNECTED
CurrentCallerID = ""
Debug.Print "Call State: CS_DISCONNECTED " & Time()
'Register
' call is disconnected
End Select
Set CallStateObject = Nothing
End Sub
Private Sub CallInfoEvent()
Debug.Print "CallInfoEvent Called " & Time()
Dim CallerID As String
YisMan
2007-09-07 13:12:02 UTC
Permalink
Oh I'm sorry. i wote that i'd post my code, but in all my excitement I forgot
all about it. here it is.

BTW one thing that i didnt fix yet, but im sure i can work around is the
fact that the callInfoChange fires again and again by each call which reopens
the customer info on the screen again and again.

And did i mention my gratidude?

Heres the entire module, I'd love to here your remarks: (just see how clean
it is!)

Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768

Private RegCookie As Integer
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object

Sub Initialize()
Dim m_TAPI As New TAPI
m_TAPI.Initialize
Set oTAPI = m_TAPI
Set m_TAPI = Nothing
End Sub

Sub Setup()
Initialize
Register
End Sub

Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent
As Object)
Dim X As Long
'For X = 0 To 100000: Next X

On Error GoTo eHandler

Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()

Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Dim oCallNotificationEvent As ITCallNotificationEvent
Set oCallNotificationEvent = pEvent

Select Case oCallNotificationEvent.Event
Case CNE_OWNER '0
Debug.Print "Call Notification: CNE_OWNER " & Time()
Case CNE_MONITOR '1
Debug.Print "Call Notification: CNE_MONITOR " & Time()
End Select

Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Dim oCallStateEvent As ITCallStateEvent
Set oCallStateEvent = pEvent
Select Case oCallStateEvent.State
Case CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
Case CS_DISCONNECTED '3
Debug.Print "Call State: CS_DISCONNECTED " & Time()
Case CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
Case CS_HOLD '5
Debug.Print "Call State: CS_HOLD " & Time()
Case CS_QUEUED '6
Debug.Print "Call State: CS_QUEUED " & Time()
End Select

Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Dim oCallInfoChangeEvent As ITCallInfoChangeEvent
Set oCallInfoChangeEvent = pEvent
Dim CallerID As String
'MsgBox "Caller ID Sleep"
'For X = 0 To 100000: Next X
CallerID =
Nz(oCallInfoChangeEvent.Call.CallInfoString(CIS_CALLERIDNUMBER), "")
HandleIncoming (CallerID)

Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
GoTo Finish
eHandler:
Debug.Print "Error #:"; Err.Number; " - "; Err.Description; " at "; Time()
If Err Then Err.Clear
For X = 0 To 100000: Next X
Resume Next

Finish:
Set oCallInfoChangeEvent = Nothing
Set oCallNotificationEvent = Nothing
Set oCallStateEvent = Nothing
End Sub


Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
End Sub

Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
For Each Address In oTAPI.Addresses ' AddressCollection ' looping
through address collection
If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if
address is working
Dim MediaSupport As ITMediaSupport
Set MediaSupport = Address ' extracting meida support interface
from the address
Dim MediaTypes As Long
MediaTypes = MediaSupport.MediaTypes ' extracting media types
supporting
Set MediaSupport = Nothing ' dispose of the object
If (MediaTypes And MediaModem) = MediaModem Then
If (MediaTypes And MediaAudio) = MediaAudio Then
Set oAddress = Address ' select this address
Exit For
End If
End If
End If
Next Address
If oAddress Is Nothing Then Exit Sub
Debug.Print "Registered at " & Time()
RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False,
MediaTypes, 1)
oTAPI.EventFilter = (1 Or 2 Or 4 Or 8 Or 16 Or 32 Or 64 Or 128 Or 256 Or
512 Or 1024 Or 2048 Or _
4096 Or 8192 Or 16384 Or 32768 Or 65536 Or 131072 Or 262144 Or
524288 Or 1048576 Or 2097152 Or 4194304 Or _
8388608 Or 16777216 Or 33554432)
End Sub


Sub HandleIncoming(stCallerID As String)
Debug.Print "Handling CID: " & stCallerID
Application.SysCmd acSysCmdSetStatus, "CID: " & stCallerID
Dim CallerID As String
CallerID = Canonical(stCallerID)
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' &
phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 & '|' &
fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then Exit Sub
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
End Sub
--
Thankfully, YisMan
Post by Matthias Moetje [MVP]
YisMan,
I am not sure why you would need a delay, and can't say without seeing your
code, but I'm glad to hear that it's at least working now!
Post by YisMan
I'm so happy! i'm working on this for two months! God is good!
Don't you always put your phone number in your posts? I want to call you to
thank you.
I'm out of words. I almost gave up already.
May God bless you with long life and all blessings!
Always glad to help! You're welcome!
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Post by Matthias Moetje [MVP]
YisMan,
Post by YisMan
Your help is truly appreciated.
Thankfully,
Thanks for your feedback, you're welcome!
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Post by Matthias Moetje [MVP]
---------------------------------------------------------------------
You MUST NOT store the event objects which you receive with TAPI
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
These objects are valid only within the event procecure and are reused
by TAPI. If you store the object pointers, TAPI cannot reuse them and
will stop firing events.
---------------------------------------------------------------------
You MUST handle errors when calling the ::CallInfoxxx methods.
When you use "On Error Resume Next", you must do
If Err Then Err.Clear
Or you create a normal event handler and call either "Err.Clear", "Resume"
or "Resume Next" or "Resume <Label>" after processing the error.
---------------------------------------------------------------------
Regarding the CallerID availability I guess the information is not available
after the first ring but just with the second ring (in analog networks the
CallerID is transmitted between the first and the second ring). Since you
store the ITCallNotificationEvent object, TAPI can't fire it a second time
when the information becomes available.
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Hello everyone,
First thanks again to Grant Schenck and Matthias Moetje for their
input
on
my previous post, titled "Monitor Incoming Calls in MS Access". With their
guidance I progressed my code pretty much.
Now to the current problem. The code that I have now recognizes incoming
calls, but occasionally retrieves the Caller ID info, though most of
the
time
doesn't. The code is below. I'm working on this for weeks, but not
making
any
progress.
It seems to me that the problem is that the registration gets lost
after
the
call to the CallInfoObject.Call.CallInfoString method. thats why Iput a
"Register" call after each call to "CallInfoString". On the other
hand
my
googling tells me that all TAPI object must be completely destroyed between
each call to CallInfoString. So I'm torn balancing between
destruction
and
reregistration, which are pretty much two opposites, and have'nt
found
the
right mix yet.
Another oddity, which I'm not positive about, and is difficult to
test
for
sure. Sometimes when the TE_CALLINFOCHANGE is raised in debugging
mode
(due
to a breakpoint) then it actually DOES get Caller ID. As if it is a timing
problem.
The entire code is simply a class module which I call MCHTapi. I
have
one
more line of code, that is a global variable declared in a regular
module
as
Public mTAPI As New MCHTapi
Here is the entire code as is. My greatest appreciation to all who are
taking the time to read this and respond to it.
Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address (you can
hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String
Dim MediaTypes As Long
'property let NewTAPI as TAPI3Lib.TAPI
'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property
'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property
Sub Setup()
'Reset
Initialize
Register
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT,
ByVal
pEvent
As Object)
' If Not CallInfoObject Is Nothing Then Debug.Print
CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()
Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub
Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and ended calls
Debug.Print "CallNotificationEvent Type " &
CallNotificationObject.Event &
"
" & Time()
Select Case CallNotificationObject.Event
Case CNE_MONITOR
' the notification is for a monitored call
Matthias Moetje [MVP]
2007-09-12 22:54:28 UTC
Permalink
Hi,

the event handling looks quite well now. I don't think that you need the
For...Next
loop in the error handler. If the error is resulting from a CallInfoxxx
method, this probably
means the information isn't available yet and you should just wait for a
subsequent
TE_CALLINFO where the information might be available.

PS: If you _really_ need to make a break, don't use a For..Next loop,
instead use the
Sleep API (search for 'Declare Sleep'). The difference is that Sleep results
in 0% CPU
usage while For..Next creates 100% CPU load. Additionally the delay time
with Sleep
does not depend on CPU processing power...


Best regards,

Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Oh I'm sorry. i wote that i'd post my code, but in all my excitement I forgot
all about it. here it is.
BTW one thing that i didnt fix yet, but im sure i can work around is the
fact that the callInfoChange fires again and again by each call which reopens
the customer info on the screen again and again.
And did i mention my gratidude?
Heres the entire module, I'd love to here your remarks: (just see how clean
it is!)
Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768
Private RegCookie As Integer
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
Sub Initialize()
Dim m_TAPI As New TAPI
m_TAPI.Initialize
Set oTAPI = m_TAPI
Set m_TAPI = Nothing
End Sub
Sub Setup()
Initialize
Register
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent
As Object)
Dim X As Long
'For X = 0 To 100000: Next X
On Error GoTo eHandler
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()
Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Dim oCallNotificationEvent As ITCallNotificationEvent
Set oCallNotificationEvent = pEvent
Select Case oCallNotificationEvent.Event
Case CNE_OWNER '0
Debug.Print "Call Notification: CNE_OWNER " & Time()
Case CNE_MONITOR '1
Debug.Print "Call Notification: CNE_MONITOR " & Time()
End Select
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Dim oCallStateEvent As ITCallStateEvent
Set oCallStateEvent = pEvent
Select Case oCallStateEvent.State
Case CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
Case CS_DISCONNECTED '3
Debug.Print "Call State: CS_DISCONNECTED " & Time()
Case CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
Case CS_HOLD '5
Debug.Print "Call State: CS_HOLD " & Time()
Case CS_QUEUED '6
Debug.Print "Call State: CS_QUEUED " & Time()
End Select
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Dim oCallInfoChangeEvent As ITCallInfoChangeEvent
Set oCallInfoChangeEvent = pEvent
Dim CallerID As String
'MsgBox "Caller ID Sleep"
'For X = 0 To 100000: Next X
CallerID =
Nz(oCallInfoChangeEvent.Call.CallInfoString(CIS_CALLERIDNUMBER), "")
HandleIncoming (CallerID)
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
GoTo Finish
Debug.Print "Error #:"; Err.Number; " - "; Err.Description; " at "; Time()
If Err Then Err.Clear
For X = 0 To 100000: Next X
Resume Next
Set oCallInfoChangeEvent = Nothing
Set oCallNotificationEvent = Nothing
Set oCallStateEvent = Nothing
End Sub
Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
End Sub
Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
For Each Address In oTAPI.Addresses ' AddressCollection ' looping
through address collection
If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if
address is working
Dim MediaSupport As ITMediaSupport
Set MediaSupport = Address ' extracting meida support interface
from the address
Dim MediaTypes As Long
MediaTypes = MediaSupport.MediaTypes ' extracting media types
supporting
Set MediaSupport = Nothing ' dispose of the object
If (MediaTypes And MediaModem) = MediaModem Then
If (MediaTypes And MediaAudio) = MediaAudio Then
Set oAddress = Address ' select this address
Exit For
End If
End If
End If
Next Address
If oAddress Is Nothing Then Exit Sub
Debug.Print "Registered at " & Time()
RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False,
MediaTypes, 1)
oTAPI.EventFilter = (1 Or 2 Or 4 Or 8 Or 16 Or 32 Or 64 Or 128 Or 256 Or
512 Or 1024 Or 2048 Or _
4096 Or 8192 Or 16384 Or 32768 Or 65536 Or 131072 Or 262144 Or
524288 Or 1048576 Or 2097152 Or 4194304 Or _
8388608 Or 16777216 Or 33554432)
End Sub
Sub HandleIncoming(stCallerID As String)
Debug.Print "Handling CID: " & stCallerID
Application.SysCmd acSysCmdSetStatus, "CID: " & stCallerID
Dim CallerID As String
CallerID = Canonical(stCallerID)
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' &
phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 & '|' &
fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then Exit Sub
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
End Sub
--
Thankfully, YisMan
Post by Matthias Moetje [MVP]
YisMan,
I am not sure why you would need a delay, and can't say without seeing your
code, but I'm glad to hear that it's at least working now!
Post by YisMan
I'm so happy! i'm working on this for two months! God is good!
Don't you always put your phone number in your posts? I want to call
you
to
thank you.
I'm out of words. I almost gave up already.
May God bless you with long life and all blessings!
Always glad to help! You're welcome!
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Post by Matthias Moetje [MVP]
YisMan,
Post by YisMan
Your help is truly appreciated.
Thankfully,
Thanks for your feedback, you're welcome!
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Post by Matthias Moetje [MVP]
---------------------------------------------------------------------
You MUST NOT store the event objects which you receive with TAPI
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
These objects are valid only within the event procecure and are reused
by TAPI. If you store the object pointers, TAPI cannot reuse them and
will stop firing events.
---------------------------------------------------------------------
You MUST handle errors when calling the ::CallInfoxxx methods.
When you use "On Error Resume Next", you must do
If Err Then Err.Clear
Or you create a normal event handler and call either "Err.Clear", "Resume"
or "Resume Next" or "Resume <Label>" after processing the error.
---------------------------------------------------------------------
Regarding the CallerID availability I guess the information is not available
after the first ring but just with the second ring (in analog
networks
the
CallerID is transmitted between the first and the second ring).
Since
you
store the ITCallNotificationEvent object, TAPI can't fire it a
second
time
when the information becomes available.
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Hello everyone,
First thanks again to Grant Schenck and Matthias Moetje for their
input
on
my previous post, titled "Monitor Incoming Calls in MS Access".
With
their
guidance I progressed my code pretty much.
Now to the current problem. The code that I have now recognizes incoming
calls, but occasionally retrieves the Caller ID info, though most of
the
time
doesn't. The code is below. I'm working on this for weeks, but not
making
any
progress.
It seems to me that the problem is that the registration gets lost
after
the
call to the CallInfoObject.Call.CallInfoString method. thats why Iput a
"Register" call after each call to "CallInfoString". On the other
hand
my
googling tells me that all TAPI object must be completely
destroyed
between
each call to CallInfoString. So I'm torn balancing between
destruction
and
reregistration, which are pretty much two opposites, and have'nt
found
the
right mix yet.
Another oddity, which I'm not positive about, and is difficult to
test
for
sure. Sometimes when the TE_CALLINFOCHANGE is raised in debugging
mode
(due
to a breakpoint) then it actually DOES get Caller ID. As if it is
a
timing
problem.
The entire code is simply a class module which I call MCHTapi. I
have
one
more line of code, that is a global variable declared in a regular
module
as
Public mTAPI As New MCHTapi
Here is the entire code as is. My greatest appreciation to all
who
are
taking the time to read this and respond to it.
Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address
(you
can
hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String
Dim MediaTypes As Long
'property let NewTAPI as TAPI3Lib.TAPI
'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property
'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property
Sub Setup()
'Reset
Initialize
Register
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT,
ByVal
pEvent
As Object)
' If Not CallInfoObject Is Nothing Then Debug.Print
CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()
Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print
CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub
Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and
ended
calls
Debug.Print "CallNotificationEvent Type " &
CallNotificationObject.Event &
"
" & Time()
Select Case CallNotificationObject.Event
Case CNE_MONITOR
' the notification is for a monitored call
YisMan
2007-09-15 18:24:01 UTC
Permalink
Hi.
Thanks again for another helpful post. (BTW, I have just realized that I
have never rated your post as "answered my question". sorry about that. I
just did that.) I realized the innefiencey of the For...Next cause on
diffrent PC's it performed differently. so I changed my error handler to:

eHandler:
Debug.Print "Error #:"; Err.Number; " - "; Err.Description; " at "; Time()
Dim e As Long
e = Err.Number
If Err Then Err.Clear
If e = -2147467259 Then
Resume CIDRetry
Else
Resume Next
End If


where CIDRetry is a label just befor the line calling the
Call.CallInfoString method. It woks very well now.

I appreciate the interest you are taking.
Thankfully,
YisMan
Post by Matthias Moetje [MVP]
Hi,
the event handling looks quite well now. I don't think that you need the
For...Next
loop in the error handler. If the error is resulting from a CallInfoxxx
method, this probably
means the information isn't available yet and you should just wait for a
subsequent
TE_CALLINFO where the information might be available.
PS: If you _really_ need to make a break, don't use a For..Next loop,
instead use the
Sleep API (search for 'Declare Sleep'). The difference is that Sleep results
in 0% CPU
usage while For..Next creates 100% CPU load. Additionally the delay time
with Sleep
does not depend on CPU processing power...
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Oh I'm sorry. i wote that i'd post my code, but in all my excitement I forgot
all about it. here it is.
BTW one thing that i didnt fix yet, but im sure i can work around is the
fact that the callInfoChange fires again and again by each call which reopens
the customer info on the screen again and again.
And did i mention my gratidude?
Heres the entire module, I'd love to here your remarks: (just see how clean
it is!)
Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768
Private RegCookie As Integer
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
Sub Initialize()
Dim m_TAPI As New TAPI
m_TAPI.Initialize
Set oTAPI = m_TAPI
Set m_TAPI = Nothing
End Sub
Sub Setup()
Initialize
Register
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent
As Object)
Dim X As Long
'For X = 0 To 100000: Next X
On Error GoTo eHandler
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()
Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Dim oCallNotificationEvent As ITCallNotificationEvent
Set oCallNotificationEvent = pEvent
Select Case oCallNotificationEvent.Event
Case CNE_OWNER '0
Debug.Print "Call Notification: CNE_OWNER " & Time()
Case CNE_MONITOR '1
Debug.Print "Call Notification: CNE_MONITOR " & Time()
End Select
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Dim oCallStateEvent As ITCallStateEvent
Set oCallStateEvent = pEvent
Select Case oCallStateEvent.State
Case CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
Case CS_DISCONNECTED '3
Debug.Print "Call State: CS_DISCONNECTED " & Time()
Case CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
Case CS_HOLD '5
Debug.Print "Call State: CS_HOLD " & Time()
Case CS_QUEUED '6
Debug.Print "Call State: CS_QUEUED " & Time()
End Select
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Dim oCallInfoChangeEvent As ITCallInfoChangeEvent
Set oCallInfoChangeEvent = pEvent
Dim CallerID As String
'MsgBox "Caller ID Sleep"
'For X = 0 To 100000: Next X
CallerID =
Nz(oCallInfoChangeEvent.Call.CallInfoString(CIS_CALLERIDNUMBER), "")
HandleIncoming (CallerID)
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
GoTo Finish
Debug.Print "Error #:"; Err.Number; " - "; Err.Description; " at "; Time()
If Err Then Err.Clear
For X = 0 To 100000: Next X
Resume Next
Set oCallInfoChangeEvent = Nothing
Set oCallNotificationEvent = Nothing
Set oCallStateEvent = Nothing
End Sub
Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
End Sub
Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
For Each Address In oTAPI.Addresses ' AddressCollection ' looping
through address collection
If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if
address is working
Dim MediaSupport As ITMediaSupport
Set MediaSupport = Address ' extracting meida support interface
from the address
Dim MediaTypes As Long
MediaTypes = MediaSupport.MediaTypes ' extracting media types
supporting
Set MediaSupport = Nothing ' dispose of the object
If (MediaTypes And MediaModem) = MediaModem Then
If (MediaTypes And MediaAudio) = MediaAudio Then
Set oAddress = Address ' select this address
Exit For
End If
End If
End If
Next Address
If oAddress Is Nothing Then Exit Sub
Debug.Print "Registered at " & Time()
RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False,
MediaTypes, 1)
oTAPI.EventFilter = (1 Or 2 Or 4 Or 8 Or 16 Or 32 Or 64 Or 128 Or 256 Or
512 Or 1024 Or 2048 Or _
4096 Or 8192 Or 16384 Or 32768 Or 65536 Or 131072 Or 262144 Or
524288 Or 1048576 Or 2097152 Or 4194304 Or _
8388608 Or 16777216 Or 33554432)
End Sub
Sub HandleIncoming(stCallerID As String)
Debug.Print "Handling CID: " & stCallerID
Application.SysCmd acSysCmdSetStatus, "CID: " & stCallerID
Dim CallerID As String
CallerID = Canonical(stCallerID)
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' &
phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 & '|' &
fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then Exit Sub
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
End Sub
--
Thankfully, YisMan
Post by Matthias Moetje [MVP]
YisMan,
I am not sure why you would need a delay, and can't say without seeing your
code, but I'm glad to hear that it's at least working now!
Post by YisMan
I'm so happy! i'm working on this for two months! God is good!
Don't you always put your phone number in your posts? I want to call
you
to
thank you.
I'm out of words. I almost gave up already.
May God bless you with long life and all blessings!
Always glad to help! You're welcome!
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Post by Matthias Moetje [MVP]
YisMan,
Post by YisMan
Your help is truly appreciated.
Thankfully,
Thanks for your feedback, you're welcome!
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
farewelldave
2007-09-16 23:16:03 UTC
Permalink
YisMan,

This is exactly what I'm needing to figure out how to do with Access. I've
got a crude but working database system for my secretary, and I've been
searching all over the internet trying to find what you're doing.

I don't know much about TAPI. I'm familiar with VBA, but not VB6 or anything
like that. From your posts, I understood that the code you posted was a
module, but wasn't sure how you are using it with Access forms, etc.

Any help would be appreciated. I've been looking around for the last few
weeks, and this is the first thing I've found that addresses my problem.

Thanks so much,

Dave Markley
***@gmail.com
Matthias Moetje [MVP]
2007-09-18 21:33:40 UTC
Permalink
YisMan,
Post by YisMan
I appreciate the interest you are taking.
Thanks again, you're welcome!


Best regards,

Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Post by Matthias Moetje [MVP]
Hi,
the event handling looks quite well now. I don't think that you need the
For...Next
loop in the error handler. If the error is resulting from a CallInfoxxx
method, this probably
means the information isn't available yet and you should just wait for a
subsequent
TE_CALLINFO where the information might be available.
PS: If you _really_ need to make a break, don't use a For..Next loop,
instead use the
Sleep API (search for 'Declare Sleep'). The difference is that Sleep results
in 0% CPU
usage while For..Next creates 100% CPU load. Additionally the delay time
with Sleep
does not depend on CPU processing power...
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Oh I'm sorry. i wote that i'd post my code, but in all my excitement I forgot
all about it. here it is.
BTW one thing that i didnt fix yet, but im sure i can work around is the
fact that the callInfoChange fires again and again by each call which reopens
the customer info on the screen again and again.
And did i mention my gratidude?
Heres the entire module, I'd love to here your remarks: (just see how clean
it is!)
Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768
Private RegCookie As Integer
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
Sub Initialize()
Dim m_TAPI As New TAPI
m_TAPI.Initialize
Set oTAPI = m_TAPI
Set m_TAPI = Nothing
End Sub
Sub Setup()
Initialize
Register
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent
As Object)
Dim X As Long
'For X = 0 To 100000: Next X
On Error GoTo eHandler
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()
Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Dim oCallNotificationEvent As ITCallNotificationEvent
Set oCallNotificationEvent = pEvent
Select Case oCallNotificationEvent.Event
Case CNE_OWNER '0
Debug.Print "Call Notification: CNE_OWNER " & Time()
Case CNE_MONITOR '1
Debug.Print "Call Notification: CNE_MONITOR " & Time()
End Select
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Dim oCallStateEvent As ITCallStateEvent
Set oCallStateEvent = pEvent
Select Case oCallStateEvent.State
Case CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
Case CS_DISCONNECTED '3
Debug.Print "Call State: CS_DISCONNECTED " & Time()
Case CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
Case CS_HOLD '5
Debug.Print "Call State: CS_HOLD " & Time()
Case CS_QUEUED '6
Debug.Print "Call State: CS_QUEUED " & Time()
End Select
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Dim oCallInfoChangeEvent As ITCallInfoChangeEvent
Set oCallInfoChangeEvent = pEvent
Dim CallerID As String
'MsgBox "Caller ID Sleep"
'For X = 0 To 100000: Next X
CallerID =
Nz(oCallInfoChangeEvent.Call.CallInfoString(CIS_CALLERIDNUMBER), "")
HandleIncoming (CallerID)
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
GoTo Finish
Debug.Print "Error #:"; Err.Number; " - "; Err.Description; " at "; Time()
If Err Then Err.Clear
For X = 0 To 100000: Next X
Resume Next
Set oCallInfoChangeEvent = Nothing
Set oCallNotificationEvent = Nothing
Set oCallStateEvent = Nothing
End Sub
Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
End Sub
Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
For Each Address In oTAPI.Addresses ' AddressCollection ' looping
through address collection
If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if
address is working
Dim MediaSupport As ITMediaSupport
Set MediaSupport = Address ' extracting meida support interface
from the address
Dim MediaTypes As Long
MediaTypes = MediaSupport.MediaTypes ' extracting media types
supporting
Set MediaSupport = Nothing ' dispose of the object
If (MediaTypes And MediaModem) = MediaModem Then
If (MediaTypes And MediaAudio) = MediaAudio Then
Set oAddress = Address ' select this address
Exit For
End If
End If
End If
Next Address
If oAddress Is Nothing Then Exit Sub
Debug.Print "Registered at " & Time()
RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False,
MediaTypes, 1)
oTAPI.EventFilter = (1 Or 2 Or 4 Or 8 Or 16 Or 32 Or 64 Or 128 Or
256
Or
512 Or 1024 Or 2048 Or _
4096 Or 8192 Or 16384 Or 32768 Or 65536 Or 131072 Or 262144 Or
524288 Or 1048576 Or 2097152 Or 4194304 Or _
8388608 Or 16777216 Or 33554432)
End Sub
Sub HandleIncoming(stCallerID As String)
Debug.Print "Handling CID: " & stCallerID
Application.SysCmd acSysCmdSetStatus, "CID: " & stCallerID
Dim CallerID As String
CallerID = Canonical(stCallerID)
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' &
phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 &
'|'
&
fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then Exit Sub
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
End Sub
--
Thankfully, YisMan
Post by Matthias Moetje [MVP]
YisMan,
I am not sure why you would need a delay, and can't say without seeing your
code, but I'm glad to hear that it's at least working now!
Post by YisMan
I'm so happy! i'm working on this for two months! God is good!
Don't you always put your phone number in your posts? I want to call
you
to
thank you.
I'm out of words. I almost gave up already.
May God bless you with long life and all blessings!
Always glad to help! You're welcome!
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Augustenstraße 24
80333 Munich, GERMANY
-------------------------------------
e-mail: moetje at terasens dot com
www: www.terasens.com
-------------------------------------
Post by YisMan
Post by Matthias Moetje [MVP]
YisMan,
Post by YisMan
Your help is truly appreciated.
Thankfully,
Thanks for your feedback, you're welcome!
Best regards,
Matthias Moetje
-------------------------------------
TAPI WIKI: http://www.tapi.info
-------------------------------------
TERASENS GmbH
Christophe
2015-10-29 11:21:33 UTC
Permalink
hello yisman,
first sorry for my bad English, I m French.
I was looking for solution to get a caller id when the phone ring
. I found your code that i have copy in access environemment.

There is an error in register sub, the code finds well the number (5) ports that i have on my box (SFR BOX)but there are a problem because each address are to 0.
So the programm stop it.

here's my/your code:

Public Montapi

'Here is the entire code as is. My greatest appreciation to all who are
'taking the time to read this and respond to it.


Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768

Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address (you can
'hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String

Dim MediaTypes As Long

' property let NewTAPI as TAPI3Lib.TAPI

'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property

'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property



Public Sub Setup()
Reset
Initialize
Register
End Sub

Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object)
Dim a As String
' If Not CallInfoObject Is Nothing Then Debug.Print
a = CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()

Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub


Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and ended calls
Debug.Print "CallNotificationEvent Type " & CallNotificationObject.Event & " " & Time()
Select Case CallNotificationObject.Event

Case CNE_MONITOR
' the notification is for a monitored call
Debug.Print "Call Notification: CNE_MONITOR " & Time()
Case CNE_OWNER
' the notification is for an owned call
Debug.Print "Call Notification: CNE_OWNER " & Time()
End Select
Set CallNotificationObject = Nothing
End Sub

Private Sub CallStateEvent()
'Debug.Print "CallStateEvent Called " & Now()
' here we should check to see call state and handle connects and
'disconnects
Dim b As String
Select Case CallStateObject.State
Case CALL_STATE.CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CALL_STATE.CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CALL_STATE.CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
' a call is offering so if you dont want it then pass it
' the code to pass the call is the following
'Dim CallControl As ITBasicCallControl = CallStateObject.Call
'CallControl.HandoffIndirect
b = CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
Case CALL_STATE.CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
' call is connected
Case CALL_STATE.CS_QUEUED
Debug.Print "Call State: CS_QUEUED " & Time()
' call is beeing queued
Case CALL_STATE.CS_HOLD
Debug.Print "Call State: CS_HOLD " & Time()
' call is on hold
Case CALL_STATE.CS_DISCONNECTED
CurrentCallerID = ""
Debug.Print "Call State: CS_DISCONNECTED " & Time()
'Register
' call is disconnected
End Select
Set CallStateObject = Nothing
End Sub

Private Sub CallInfoEvent()
Debug.Print "CallInfoEvent Called " & Time()
Dim CallerID As String
On Error Resume Next
CallerID = Nz(CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER), "")
On Error GoTo 0
Application.SysCmd acSysCmdSetStatus, "CID: " & CallerID

'Set CallInfoObject = Nothing
If CallerID = "" Or CallerID = CurrentCallerID Then GoTo Finish
Debug.Print "Last Caller: " & CurrentCallerID
CurrentCallerID = CallerID
'If CallerID = "" Then CallerID = "0527649971"
Debug.Print "Caller ID: "; CallerID
' CallerID = can(CallerID)' canonical pour masque de saisie????
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' & phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 & '|' & fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then GoTo Finish
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
'ResetTapi


Finish:
Shutdown
Initialize
Register
End Sub

Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
Set CallNotificationObject = Nothing
Set CallStateObject = Nothing
Set CallInfoObject = Nothing
End Sub

Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
For Each Address In oTAPI.Addresses ' AddressCollection ' looping

'through address collection
If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if
'address is working
Debug.Print "Registered at " & Time()
Dim MediaSupport As ITMediaSupport
Set MediaSupport = Address ' extracting media support interface
'from the address
MediaTypes = MediaSupport.MediaTypes ' extracting media types
'supporting
Set MediaSupport = Nothing ' dispose of the object
If (MediaTypes And MediaModem) = MediaModem Then
If (MediaTypes And MediaAudio) = MediaAudio Then
Set oAddress = Address ' select this address

Exit For
End If
End If
End If
Next Address
If oAddress Is Nothing Then Exit Sub
Debug.Print "Registered at " & Time()
RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False, MediaTypes, 1)
oTAPI.EventFilter = (1 Or 2 Or 4 Or 8 Or 16 Or 32 Or 64 Or 128 Or 256 Or 512 Or 1024 Or 2048 Or 4096 Or 8192 Or 16384 Or 32768 Or 65536 Or 131072 Or 262144 Or 524288 Or 1048576 Or 2097152 Or 4194304 Or 8388608 Or 16777216 Or 33554432)
End Sub

Sub Initialize()
Dim m_TAPI As New TAPI
m_TAPI.Initialize
Set oTAPI = m_TAPI
Set m_TAPI = Nothing
End Sub


many thans fo your help if you can!!!
Christophe
2015-10-30 16:06:59 UTC
Permalink
Post by YisMan
Hello everyone,
I put again my code because the fist one was'nt very good. Thanks for your help.
Oh, I just repeat than everyting is to nothing:
There is just 5 iterations in the sub register ansd then the code stop running.

Public Montapi

'Here is the entire code as is. My greatest appreciation to all who are



Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768

Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address (you can
'hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String

Dim MediaTypes As Long

' property let NewTAPI as TAPI3Lib.TAPI

'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property

'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property



Public Sub Setup()
Reset
Initialize
Register
End Sub

Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object)
Dim a As String
' If Not CallInfoObject Is Nothing Then Debug.Print
a = CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()

Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub


Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and ended calls
Debug.Print "CallNotificationEvent Type " & CallNotificationObject.Event & " " & Time()
Select Case CallNotificationObject.Event

Case CNE_MONITOR
' the notification is for a monitored call
Debug.Print "Call Notification: CNE_MONITOR " & Time()
Case CNE_OWNER
' the notification is for an owned call
Debug.Print "Call Notification: CNE_OWNER " & Time()
End Select
Set CallNotificationObject = Nothing
End Sub

Private Sub CallStateEvent()
'Debug.Print "CallStateEvent Called " & Now()
' here we should check to see call state and handle connects and
'disconnects
Dim b As String
Select Case CallStateObject.State
Case CALL_STATE.CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CALL_STATE.CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CALL_STATE.CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
' a call is offering so if you dont want it then pass it
' the code to pass the call is the following
'Dim CallControl As ITBasicCallControl = CallStateObject.Call
'CallControl.HandoffIndirect
b = CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
Case CALL_STATE.CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
' call is connected
Case CALL_STATE.CS_QUEUED
Debug.Print "Call State: CS_QUEUED " & Time()
' call is beeing queued
Case CALL_STATE.CS_HOLD
Debug.Print "Call State: CS_HOLD " & Time()
' call is on hold
Case CALL_STATE.CS_DISCONNECTED
CurrentCallerID = ""
Debug.Print "Call State: CS_DISCONNECTED " & Time()
'Register
' call is disconnected
End Select
Set CallStateObject = Nothing
End Sub

Private Sub CallInfoEvent()
Debug.Print "CallInfoEvent Called " & Time()
Dim CallerID As String
On Error Resume Next
CallerID = Nz(CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER), "")
On Error GoTo 0
Application.SysCmd acSysCmdSetStatus, "CID: " & CallerID

'Set CallInfoObject = Nothing
If CallerID = "" Or CallerID = CurrentCallerID Then GoTo Finish
Debug.Print "Last Caller: " & CurrentCallerID
CurrentCallerID = CallerID
'If CallerID = "" Then CallerID = "0527649971"
Debug.Print "Caller ID: "; CallerID
' CallerID = can(CallerID)' canonical pour masque de saisie????
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' & phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 & '|' & fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then GoTo Finish
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
'ResetTapi


Finish:
Shutdown
Initialize
Register
End Sub

Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
Set CallNotificationObject = Nothing
Set CallStateObject = Nothing
Set CallInfoObject = Nothing
End Sub

Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
For Each Address In oTAPI.Addresses ' AddressCollection ' looping

'through address collection
If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if
'address is working
Debug.Print "Registered at " & Time()
Dim MediaSupport As ITMediaSupport
Set MediaSupport = Address ' extracting media support interface
'from the address
MediaTypes = MediaSupport.MediaTypes ' extracting media types
'supporting
Set MediaSupport = Nothing ' dispose of the object
If (MediaTypes And MediaModem) = MediaModem Then
If (MediaTypes And MediaAudio) = MediaAudio Then
Set oAddress = Address ' select this address

Exit For
End If
End If
End If
Next Address
If oAddress Is Nothing Then Exit Sub
Debug.Print "Registered at " & Time()
RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False, MediaTypes, 1)
oTAPI.EventFilter = (1 Or 2 Or 4 Or 8 Or 16 Or 32 Or 64 Or 128 Or 256 Or 512 Or 1024 Or 2048 Or 4096 Or 8192 Or 16384 Or 32768 Or 65536 Or 131072 Or 262144 Or 524288 Or 1048576 Or 2097152 Or 4194304 Or 8388608 Or 16777216 Or 33554432)
End Sub

Sub Initialize()
Dim m_TAPI As New TAPI
m_TAPI.Initialize
Set oTAPI = m_TAPI
Set m_TAPI = Nothing
End Sub
Christophe
2015-10-31 12:16:34 UTC
Permalink
Post by YisMan
Hello everyone,
First thanks again to Grant Schenck and Matthias Moetje for their input on
my previous post, titled "Monitor Incoming Calls in MS Access". With their
guidance I progressed my code pretty much.
Now to the current problem. The code that I have now recognizes incoming
calls, but occasionally retrieves the Caller ID info, though most of the time
doesn't. The code is below. I'm working on this for weeks, but not making any
progress.
It seems to me that the problem is that the registration gets lost after the
call to the CallInfoObject.Call.CallInfoString method. thats why Iput a
"Register" call after each call to "CallInfoString". On the other hand my
googling tells me that all TAPI object must be completely destroyed between
each call to CallInfoString. So I'm torn balancing between destruction and
reregistration, which are pretty much two opposites, and have'nt found the
right mix yet.
Another oddity, which I'm not positive about, and is difficult to test for
sure. Sometimes when the TE_CALLINFOCHANGE is raised in debugging mode (due
to a breakpoint) then it actually DOES get Caller ID. As if it is a timing
problem.
The entire code is simply a class module which I call MCHTapi. I have one
more line of code, that is a global variable declared in a regular module as
Public mTAPI As New MCHTapi
Here is the entire code as is. My greatest appreciation to all who are
taking the time to read this and respond to it.
Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768
Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address (you can
hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String
Dim MediaTypes As Long
'property let NewTAPI as TAPI3Lib.TAPI
'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property
'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property
Sub Setup()
'Reset
Initialize
Register
End Sub
Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent
As Object)
' If Not CallInfoObject Is Nothing Then Debug.Print
CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()
Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub
Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and ended calls
Debug.Print "CallNotificationEvent Type " & CallNotificationObject.Event & "
" & Time()
Select Case CallNotificationObject.Event
Case CNE_MONITOR
' the notification is for a monitored call
Debug.Print "Call Notification: CNE_MONITOR " & Time()
Case CNE_OWNER
' the notification is for an owned call
Debug.Print "Call Notification: CNE_OWNER " & Time()
End Select
Set CallNotificationObject = Nothing
End Sub
Private Sub CallStateEvent()
'Debug.Print "CallStateEvent Called " & Now()
' here we should check to see call state and handle connects and
disconnects
Select Case CallStateObject.State
Case CALL_STATE.CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CALL_STATE.CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CALL_STATE.CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
' a call is offering so if you dont want it then pass it
' the code to pass the call is the following
'Dim CallControl As ITBasicCallControl = CallStateObject.Call
'CallControl.HandoffIndirect
(CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
Case CALL_STATE.CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
' call is connected
Case CALL_STATE.CS_QUEUED
Debug.Print "Call State: CS_QUEUED " & Time()
' call is beeing queued
Case CALL_STATE.CS_HOLD
Debug.Print "Call State: CS_HOLD " & Time()
' call is on hold
Case CALL_STATE.CS_DISCONNECTED
CurrentCallerID = ""
Debug.Print "Call State: CS_DISCONNECTED " & Time()
'Register
' call is disconnected
End Select
Set CallStateObject = Nothing
End Sub
Private Sub CallInfoEvent()
Debug.Print "CallInfoEvent Called " & Time()
Dim CallerID As String
On Error Resume Next
CallerID = Nz(CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER), "")
On Error GoTo 0
Application.SysCmd acSysCmdSetStatus, "CID: " & CallerID
'Set CallInfoObject = Nothing
If CallerID = "" Or CallerID = CurrentCallerID Then GoTo Finish
Debug.Print "Last Caller: " & CurrentCallerID
CurrentCallerID = CallerID
'If CallerID = "" Then CallerID = "0527649971"
Debug.Print "Caller ID: "; CallerID
CallerID = Canonical(CallerID)
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' &
phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 & '|' &
fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then GoTo Finish
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
'ResetTapi
Shutdown
Initialize
Register
End Sub
Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
Set CallNotificationObject = Nothing
Set CallStateObject = Nothing
Set CallInfoObject = Nothing
End Sub
Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
For Each Address In oTAPI.Addresses ' AddressCollection ' looping
through address collection
If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if
address is working
Dim MediaSupport As ITMediaSupport
Set MediaSupport = Address ' extracting meida support interface
from the address
MediaTypes = MediaSupport.MediaTypes ' extracting media types
supporting
Set MediaSupport = Nothing ' dispose of the object
If (MediaTypes And MediaModem) = MediaModem Then
If (MediaTypes And MediaAudio) = MediaAudio Then
Set oAddress = Address ' select this address
Exit For
End If
End If
End If
Next Address
If oAddress Is Nothing Then Exit Sub
Debug.Print "Registered at " & Time()
RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False,
MediaTypes, 1)
oTAPI.EventFilter = (1 Or 2 Or 4 Or 8 Or 16 Or 32 Or 64 Or 128 Or 256 Or
512 Or 1024 Or 2048 Or _
4096 Or 8192 Or 16384 Or 32768 Or 65536 Or 131072 Or 262144 Or
524288 Or 1048576 Or 2097152 Or 4194304 Or _
8388608 Or 16777216 Or 33554432)
End Sub
Sub Initialize()
Dim m_TAPI As New TAPI
m_TAPI.Initialize
Set oTAPI = m_TAPI
Set m_TAPI = Nothing
End Sub
Thankfully, YisMan
--Ever stop to think, and then forget to start again?
hi everybody and yisman: here's the code
Public Montapi

'Here is the entire code as is.

Option Explicit
Const MediaAudio As Integer = 8
Const MediaModem As Integer = 16
Const MediaFax As Integer = 32
Const MediaVideo As Long = 32768

Public WithEvents oTAPI As TAPI3Lib.TAPI ' will hold our TAPI object
'Private oAddress As ITAddress ' will hold our selected address (you can
'hold many address in an array)
Private RegCookie As Integer
Private CallNotificationObject As ITCallNotificationEvent
Private CallStateObject As ITCallStateEvent
Private CallInfoObject As ITCallInfoChangeEvent
Private CurrentCallerID As String

Dim MediaTypes As Long

' property let NewTAPI as TAPI3Lib.TAPI

'Public Property Let NewTAPI(objTapi As TAPI)
'Set oTAPI = objTapi
'Setup
'End Property

'Public Property Get NewTAPI() As TAPI3Lib.TAPI
'Set NewTAPI = oTAPI
'End Property



Public Sub Setup()
'Reset
Initialize
Register
End Sub

Private Sub oTAPI_Event(ByVal TapiEvent As TAPI3Lib.TAPI_EVENT, ByVal pEvent As Object)
Dim a As String
' If Not CallInfoObject Is Nothing Then Debug.Print
a = CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
'Debug.Print "Type " & TapiEvent & " Event Raised at " & Time()
Select Case TapiEvent
Case TE_TAPIOBJECT '1
Debug.Print "TE_TAPIOBJECT Event Raised at " & Time()
Case TE_ADDRESS '2
Debug.Print "TE_ADDRESS Event Raised at " & Time()

Case TE_CALLNOTIFICATION '4
Debug.Print "TE_CALLNOTIFICATION Event Raised at " & Time()
Set CallNotificationObject = pEvent
CallNotificationEvent
Case TE_CALLSTATE '8
Debug.Print "TE_CALLSTATE Event Raised at " & Time()
Set CallStateObject = pEvent
CallStateEvent
Case TE_CALLMEDIA '16
Debug.Print "TE_CALLMEDIA Event Raised at " & Time()
Case TE_CALLHUB '32
Debug.Print "TE_CALLHUB Event Raised at " & Time()
Case TE_CALLINFOCHANGE '64
Debug.Print "TE_CALLINFOCHANGE Event Raised at " & Time()
Set CallInfoObject = pEvent
CallInfoEvent
Case TE_PRIVATE '128
Debug.Print "TE_PRIVATE Event Raised at " & Time()
Case TE_REQUEST '256
Debug.Print "TE_REQUEST Event Raised at " & Time()
Case TE_AGENT '512
Debug.Print "TE_AGENT Event Raised at " & Time()
Case TE_AGENTSESSION '1024
Debug.Print "TE_AGENTSESSION Event Raised at " & Time()
Case TE_QOSEVENT '2048
Debug.Print "TE_QOSEVENT Event Raised at " & Time()
Case TE_AGENTHANDLER '4096
Debug.Print "TE_AGENTHANDLER Event Raised at " & Time()
Case TE_ACDGROUP '8192
Debug.Print "TE_ACDGROUP Event Raised at " & Time()
Case TE_QUEUE '16384
Debug.Print "TE_QUEUE Event Raised at " & Time()
Case TE_DIGITEVENT '32768
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_GENERATEEVENT '65536
Debug.Print "TE_DIGITEVENT Event Raised at " & Time()
Case TE_ASRTERMINAL '131072
Debug.Print "TE_ASRTERMINAL Event Raised at " & Time()
Case TE_TTSTERMINAL '262144
Debug.Print "TE_TTSTERMINAL Event Raised at " & Time()
Case TE_FILETERMINAL '524288
Debug.Print "TE_FILETERMINAL Event Raised at " & Time()
Case TE_TONETERMINAL '1048576
Debug.Print "TE_TONETERMINAL Event Raised at " & Time()
Case TE_PHONEEVENT '2097152
Debug.Print "TE_PHONEEVENT Event Raised at " & Time()
Case TE_TONEEVENT '4194304
Debug.Print "TE_TONEEVENT Event Raised at " & Time()
Case TE_GATHERDIGITS '8388608
Debug.Print "TE_GATHERDIGITS Event Raised at " & Time()
Case TE_ADDRESSDEVSPECIFIC '16777216
Debug.Print "TE_ADDRESSDEVSPECIFIC Event Raised at " & Time()
Case TE_PHONEDEVSPECIFIC '33554432
Debug.Print "TE_PHONEDEVSPECIFIC Event Raised at " & Time()
End Select
'ResetTapi
'On Error Resume Next
'Debug.Print CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER)
End Sub


Private Sub CallNotificationEvent()
' here we should check to see various notifications of new and ended calls
Debug.Print "CallNotificationEvent Type " & CallNotificationObject.Event & " " & Time()
Select Case CallNotificationObject.Event

Case CNE_MONITOR
' the notification is for a monitored call
Debug.Print "Call Notification: CNE_MONITOR " & Time()
Case CNE_OWNER
' the notification is for an owned call
Debug.Print "Call Notification: CNE_OWNER " & Time()
End Select
Set CallNotificationObject = Nothing
End Sub

Private Sub CallStateEvent()
'Debug.Print "CallStateEvent Called " & Now()
' here we should check to see call state and handle connects and
'disconnects
Dim b As String
Select Case CallStateObject.State
Case CALL_STATE.CS_IDLE '0
Debug.Print "Call State: CS_IDLE " & Time()
Case CALL_STATE.CS_INPROGRESS '1
Debug.Print "Call State: CS_INPROGRESS " & Time()
Case CALL_STATE.CS_OFFERING '4
Debug.Print "Call State: CS_OFFERING " & Time()
' a call is offering so if you dont want it then pass it
' the code to pass the call is the following
'Dim CallControl As ITBasicCallControl = CallStateObject.Call
'CallControl.HandoffIndirect
b = CallStateObject.Call.CallInfoLong(CALLINFO_LONG.CIL_MEDIATYPESAVAILABLE)
Case CALL_STATE.CS_CONNECTED '2
Debug.Print "Call State: CS_CONNECTED " & Time()
' call is connected
Case CALL_STATE.CS_QUEUED
Debug.Print "Call State: CS_QUEUED " & Time()
' call is beeing queued
Case CALL_STATE.CS_HOLD
Debug.Print "Call State: CS_HOLD " & Time()
' call is on hold
Case CALL_STATE.CS_DISCONNECTED
CurrentCallerID = ""
Debug.Print "Call State: CS_DISCONNECTED " & Time()
'Register
' call is disconnected
End Select
Set CallStateObject = Nothing
End Sub

Private Sub CallInfoEvent()
Debug.Print "CallInfoEvent Called " & Time()
Dim CallerID As String
On Error Resume Next
CallerID = Nz(CallInfoObject.Call.CallInfoString(CIS_CALLERIDNUMBER), "")
On Error GoTo 0
Application.SysCmd acSysCmdSetStatus, "CID: " & CallerID

'Set CallInfoObject = Nothing
If CallerID = "" Or CallerID = CurrentCallerID Then GoTo Finish
Debug.Print "Last Caller: " & CurrentCallerID
CurrentCallerID = CallerID
'If CallerID = "" Then CallerID = "0527649971"
Debug.Print "Caller ID: "; CallerID
' CallerID = can(CallerID)' canonical pour masque de saisie????
Dim PersonID As Integer
PersonID = Nz(DLookup("personid", "persons", "instr(phone1 & '|' & phone2 & '|' & phonework & '|' & cell1 & '|' & cell2 & '|' & cell3 & '|' & fax1 & '|' & fax2,'" & CallerID & "')"))
If PersonID = 0 Then GoTo Finish
DoCmd.OpenForm "frperson", , , "personid=" & PersonID
Forms("frperson").lbCalling.Visible = True
Application.SysCmd acSysCmdClearStatus
'ResetTapi


Finish:
Shutdown
Initialize
Register
End Sub

Sub Shutdown()
oTAPI.Shutdown
Set oTAPI = Nothing
Set CallNotificationObject = Nothing
Set CallStateObject = Nothing
Set CallInfoObject = Nothing
End Sub

Sub Register()
Dim Address As ITAddress
Dim oAddress As ITAddress
For Each Address In oTAPI.Addresses ' AddressCollection ' looping

'through address collection
If Address.State = ADDRESS_STATE.AS_INSERVICE Then ' checking if
'address is working
Debug.Print "Registered at " & Time()
Dim MediaSupport As ITMediaSupport
Set MediaSupport = Address ' extracting media support interface
'from the address
MediaTypes = MediaSupport.MediaTypes ' extracting media types
'supporting
Set MediaSupport = Nothing ' dispose of the object
If (MediaTypes And MediaModem) = MediaModem Then
If (MediaTypes And MediaAudio) = MediaAudio Then
Set oAddress = Address ' select this address

Exit For
End If
End If
End If
Next Address
If oAddress Is Nothing Then Exit Sub
Debug.Print "Registered at " & Time()
RegCookie = oTAPI.RegisterCallNotifications(oAddress, True, False, MediaTypes, 1)
oTAPI.EventFilter = (1 Or 2 Or 4 Or 8 Or 16 Or 32 Or 64 Or 128 Or 256 Or 512 Or 1024 Or 2048 Or 4096 Or 8192 Or 16384 Or 32768 Or 65536 Or 131072 Or 262144 Or 524288 Or 1048576 Or 2097152 Or 4194304 Or 8388608 Or 16777216 Or 33554432)
End Sub

Sub Initialize()
Dim m_TAPI As New TAPI
m_TAPI.Initialize
Set oTAPI = m_TAPI
Set m_TAPI = Nothing
End Sub

Loading...