
NewMail event does not occur during startup
Quote:
> I have Outlook 2002 setup to receive email from 2 POP3
> email accounts. When new mail arrives a rule runs that
> moves the new messages to different folders depending on
> the account name. This works great when Outlook is
> already open and the automatic send/receive occurs at 3
> minute intervals. For some reason this does not work when
> Outlook 2002 is first opened and I have new mail. The new
> mail is received but the rule does not run. After further
> investigation I have found that the Application_NewMail
> event is not occuring. Here is the order in which the
> events occur during startup. Application_Startup >
> Application_MapiLogonComplete > The automatic Send/Receive
> occurs > The New mail is received, but the
> Apllication_NewMail does not occur, thus the rule does not
> run.
Hiya Greg (and all you others suffering this affliction)
I've just recently (last day or so) joined this group and noticed this
thread (amongst others) and I too am annoyed with this behaviour in Outlook
(I'm sure I remember the same thing happening in Outlook 2000). So fed up
was I that I thought I'd write a bit of VBA to cover it.
Well this code works for me, let me break it down for you:
1. Outlook Starts
2. Disable the Scheduled Send/Receive
3. Pause for 10 seconds (works for me, your mileage may vary)
4. Force a Send/Receive for all accounts
4. Re-enable the Scheduled Send/Receive
and here's the code:
-----
Private Sub Application_Startup()
Dim datStartTime As Date
Dim intInterval As Integer
Dim objControl As CommandBarButton
Set objControl = ActiveExplorer.CommandBars.FindControl(ID:=6867)
If objControl.State = msoButtonUp Then
objControl.Execute
End If
' pause (10 seconds)
intInterval = 10
datStartTime = Now()
Do Until DateDiff("s", datStartTime, Now()) >= intInterval
DoEvents
Loop
' Send/Receive now
Set objControl = ActiveExplorer.CommandBars.FindControl(ID:=7095)
objControl.Execute
' Re-enable the Schedule
Set objControl = ActiveExplorer.CommandBars.FindControl(ID:=6867)
If objControl.State = msoButtonDown Then
objControl.Execute
End If
Set objControl = Nothing
End Sub
---
Now I know this is one hell of a kludge, but it works for me. The
FindControl(ID:=????) might be different in Outlook 2000 so you may want to
check this prior to running this code in the Application_Startup event.
I did try running the disable part in the Application_Quit event, but
there's no Explorers running at that point.
Any amendments/critisisms/praise, please don't hesitate.
Meddler
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.330 / Virus Database: 184 - Release Date: 28/02/2002