0
我正在使用下面的两个代码之一下载Outlook邮件,另一个更新它。第一个下载邮件的代码没有问题。但是,当我使用第二个代码来查找任务并对相应的记录集进行一些添加时,有时错误的记录集正在更新可以帮助我吗? 的senttime和sentto是反映了错误的任务如何编辑匹配记录集?
首先代码:
Private Sub getml()
Dim rst As DAO.Recordset
Dim OlApp As Outlook.Application
Dim inbox As Outlook.MAPIFolder
Dim inboxItems As Outlook.Items
Dim Mailobject As Object
Dim db As DAO.Database
Dim var As variant
Set db = CurrentDb
Set OlApp = CreateObject("Outlook.Application")
Set inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox)
Set rst= CurrentDb.OpenRecordset("mls")
Set inboxItems = inbox.Items
On error resume next
For Each Mailobject In inboxItems
set var = MailObject.UserProperties.Find("taskID")
IF Not (var Is Nothing) Then
With rst
.FindFirst "task=" Chr(34) & var & Chr(34)
If .NoMatch then
.AddNew
!task= var.value & ""
.Update
Mailobject.UnRead = False
End If
End With
End If
Next
Set OlApp = Nothing
Set inbox = Nothing
Set inboxItems = Nothing
Set Mailobject = Nothing
End sub
二码
Private Sub stml()
Dim rst As DAO.Recordset
Dim OlApp As Outlook.Application
Dim inbox As Outlook.MAPIFolder
Dim inboxItems As Outlook.Items
Dim Mailobject As Object
Dim db As DAO.Database
Dim var As variant
Set db = CurrentDb
Set OlApp = CreateObject("Outlook.Application")
Set inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFolderSentMail)
Set rst= CurrentDb.OpenRecordset("mls")
Set inboxItems = inbox.Items
On error resume next
For Each Mailobject In inboxItems
set var = MailObject.UserProperties.Find("taskID")
IF Not (var Is Nothing) Then
With rst
.FindFirst "task=" Chr(34) & var & Chr(34)
If not .NoMatch then
.edit
!senttime= MailObject.Receivedtime
!sentto = mailobject.to
.Update
Mailobject.UnRead = False
End If
End With
End If
Next
Set OlApp = Nothing
Set inbox = Nothing
Set inboxItems = Nothing
Set Mailobject = Nothing
End sub