New mail event doesn't work all time

D

DavidE

Hi,

I created a com add-in that fires an event when a new mail arrives. This is
the code:
Private WithEvents objNS As Outlook.NameSpace
Private WithEvents colItems As Outlook.Items

Private Sub Application_Startup()
Set objNS = Application.GetNamespace("MAPI") 'NameSpace Object
Set colItems = objNS.GetDefaultFolder(olFolderInbox).Items
....
End Sub

Private Sub colItems_ItemAdd(ByVal Item As Object)
Code to handle incoming mail
End Sub

Usually, this code does the work but some times it doesn't. When it stop
working the event doesn't fire for all incoming mails. I fix it by closing
and reopen the outlook. When the outlook is reopen it loads the add-in.Some
times I need to restart the computer. I tried to solve this problem by
cretaing a schedule task for a bat file that contain a regsvr32 command for
this dll but it doesn't solve the problem. I don't think that it's a problem
of code but I think that it's a problem of the outlook that unload the add-in
without a logical reason.

I'll glad to get help for this problem.

Thanks,

David
 
K

Ken Slovak - [MVP - Outlook]

ItemAdd will fail to fire if 16 or more items are added to the Inbox at a
time. That's a hard limitation from MAPI. Your code may be disabled if you
have errors and aren't trapping or handling them.
 
D

DavidE

Hi Ken,
Thanks for your reply.

I don't think that those are the cases because I never get 16 mails at once
and I don't see any error messeges when the ItemAdd fails, which I should see
if an unhandled error occur.

Let me know if there other reasons for this problem.

David
 
K

Ken Slovak - [MVP - Outlook]

Is this a COM addin, or Outlook VBA macro code? We're talking about 2
different things.

The code looks like Outlook VBA code, especially with the
Application_Startup() initialization.

You might not see an error message, depending on what level the error
occurred at. It would serve to disable your macro code though. Are you
assuming everything that comes in is a mail item? It might be a meeting
request, task request, etc.

In general, if VBA code works in most situations but gets disabled from time
to time it's a matter of error handling or logic errors.
 
D

DavidE

Hi Ken,

This is a COM AddIn. I create it with VB6.I have a deafult template of
outlook project on it and then I use the dll to install it on users machines.
I check everything that come if it's "IPM.Note"
FormDescription.MessageClass. If it is the code is process.

Is there anything else to check in addition to check the logic again ?

Thanks
David
 
K

Ken Slovak - [MVP - Outlook]

If this is a COM addin why are you using the Application_Startup()
procedure? In many or most cases it will fire before your addin is started
by Outlook. You would want to use either the On_Connection event handler or
the On_StartupComplete event handler provided by the IDTExtensibility2
interface.
 
D

DavidE

Hi Ken,
Sorry for my late reply,I wasn't here.

I'll try to work with those events.

Thanks,

David
 

Ask a Question

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

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

Ask a Question

Top