V
vonClausowitz
Hi All,
I have a problem now for some time which I really can't break.
There is nothing to pin it down on, sometimes it's there sometimes not.
I use two different email account to which I have access.
Emails come in two both accounts. The emails are the same (so send to
both accounts).
Now I created a function that will compare two email folders (one in my
own account and one in my collegaes account). First I read all the
messages in both accounts into two access tables.
I use From, To, Subject, Date Send. When the tables are filled I run a
compare query which looks at the Subject and the Day and the Month in
the Date Send. If these three are the same we have a double email.
MyQuery = "SELECT DISTINCT tblInbox.From, tblInbox.Subject,
tblInbox.Received, " & _
"tblInbox.SentDTG From tblDeletedItems, tblInbox " & _
"Where (((tblInbox.From) Is Not Null) And ((tblInbox.Subject)
" & _
"Is Not Null And (tblInbox.Subject) =
[tblDeletedItems].[Subject]) " & _
"And ((Month([tblInbox].[SentDTG])) =
Month([tblDeletedItems].[SentDTG])) " & _
"And ((Day([tblInbox].[SentDTG])) =
Day([tblDeletedItems].[SentDTG]))) ORDER BY tblInbox.Received DESC"
The query is displayed in a DBgrid and always shows the right amount of
double emails.
Now I want to check all the emails in my own email folder and when they
exist in the Query I flag them.
Finally all the flagged emails are removed from my emailfolder and
those which do not exist in the other accounts folder remain in my own
folder.
The problem is that not all the double emails get flagged, even they
exist in the Query.
This is my code:
Private Sub cmdDelSel_Click()
Dim olMailItem As Outlook.MailItem
Dim iNumItems, i As Long
Dim rst As Recordset
Dim qdf As QueryDef
Set qdf = dbSettings.QueryDefs("Query1")
Set rst = qdf.OpenRecordset
iNumItems = olOwnDeleteFolder.Items.Count
olOwnDeleteFolder.Items.Sort ("[Received]"), True
If iNumItems <> 0 Then
For i = 1 To iNumItems
Do While rst.EOF = False
Set olMailItem = olOwnDeleteFolder.Items.Item(i)
If olMailItem.Class = olMail Then
If rst("Subject") = Left(olMailItem.Subject, 255) Then
olMailItem.FlagStatus = olFlagMarked
olMailItem.Save
Exit Do
End If
End If 'olMailItem.Class = olMail
rst.MoveNext
Loop
If rst.RecordCount <> 0 Then rst.MoveFirst
Next i
End If
End Sub
Like I said sometimes it works fine but sometimes it don't.
I have been thinking about characters in the Subject strings or
something with the counter but I don't think that's the problem.
Hope anyone can help me out for I have tried everthing within my range.
Regards
Marco
I have a problem now for some time which I really can't break.
There is nothing to pin it down on, sometimes it's there sometimes not.
I use two different email account to which I have access.
Emails come in two both accounts. The emails are the same (so send to
both accounts).
Now I created a function that will compare two email folders (one in my
own account and one in my collegaes account). First I read all the
messages in both accounts into two access tables.
I use From, To, Subject, Date Send. When the tables are filled I run a
compare query which looks at the Subject and the Day and the Month in
the Date Send. If these three are the same we have a double email.
MyQuery = "SELECT DISTINCT tblInbox.From, tblInbox.Subject,
tblInbox.Received, " & _
"tblInbox.SentDTG From tblDeletedItems, tblInbox " & _
"Where (((tblInbox.From) Is Not Null) And ((tblInbox.Subject)
" & _
"Is Not Null And (tblInbox.Subject) =
[tblDeletedItems].[Subject]) " & _
"And ((Month([tblInbox].[SentDTG])) =
Month([tblDeletedItems].[SentDTG])) " & _
"And ((Day([tblInbox].[SentDTG])) =
Day([tblDeletedItems].[SentDTG]))) ORDER BY tblInbox.Received DESC"
The query is displayed in a DBgrid and always shows the right amount of
double emails.
Now I want to check all the emails in my own email folder and when they
exist in the Query I flag them.
Finally all the flagged emails are removed from my emailfolder and
those which do not exist in the other accounts folder remain in my own
folder.
The problem is that not all the double emails get flagged, even they
exist in the Query.
This is my code:
Private Sub cmdDelSel_Click()
Dim olMailItem As Outlook.MailItem
Dim iNumItems, i As Long
Dim rst As Recordset
Dim qdf As QueryDef
Set qdf = dbSettings.QueryDefs("Query1")
Set rst = qdf.OpenRecordset
iNumItems = olOwnDeleteFolder.Items.Count
olOwnDeleteFolder.Items.Sort ("[Received]"), True
If iNumItems <> 0 Then
For i = 1 To iNumItems
Do While rst.EOF = False
Set olMailItem = olOwnDeleteFolder.Items.Item(i)
If olMailItem.Class = olMail Then
If rst("Subject") = Left(olMailItem.Subject, 255) Then
olMailItem.FlagStatus = olFlagMarked
olMailItem.Save
Exit Do
End If
End If 'olMailItem.Class = olMail
rst.MoveNext
Loop
If rst.RecordCount <> 0 Then rst.MoveFirst
Next i
End If
End Sub
Like I said sometimes it works fine but sometimes it don't.
I have been thinking about characters in the Subject strings or
something with the counter but I don't think that's the problem.
Hope anyone can help me out for I have tried everthing within my range.
Regards
Marco