错误91:对象变量或块变量未设置需要帮助
问题描述:
我试图使用下面的给定过程来下载唯一的邮件,但出现错误(91对象变量或块变量未设置) 错误行:。 FindFirst "task =""" & Mailobject.UserProperties.Find("taskID") & """"
错误91:对象变量或块变量未设置需要帮助
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 dealer As Integer
Set db = CurrentDb
Set OlApp = CreateObject("Outlook.Application")
Set inbox = OlApp.GetNamespace("Mapi").GetDefaultFolder(olFolderInbox)
Set rst= CurrentDb.OpenRecordset("mls")
Set inboxItems = inbox.Items
For Each Mailobject In inboxItems
With rst
.FindFirst "task =""" & Mailobject.UserProperties.Find("taskID") & """"
If .NoMatch
.AddNew
!task= Mailobject.UserProperties.Find("taskID")
!tsktml= Mailobject.UserProperties.Find("timeline")
.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
答
此错误是指一些bug在你的记录集对象(它要么没有设置正确,或者.FindFirst
运行之前已关闭)。
我无法使用您提供的代码进行复制,因此您需要自行解决此问题。
您可以经常通过删除With
块得到更多的描述性错误:
For Each Mailobject In inboxItems
rst.FindFirst "task =""" & Mailobject.UserProperties.Find("taskID") & """"
If rst.NoMatch
rst.AddNew
rst!task= Mailobject.UserProperties.Find("taskID")
rst!tsktml= Mailobject.UserProperties.Find("timeline")
rst.Update
Mailobject.UnRead = False
End If
End If
答
尝试更换
Set rst= CurrentDb.OpenRecordset("mls")
通过
Set rst= db.OpenRecordset("mls")
+0
我试过这个,但仍然收到错误 – Supernova
答
最后,这是我已经处理了错误
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
我试图调试代码并找出错误。变体var在搜索完所有邮件后显示空值。即var返回taskid直到最后一封邮件,但在搜索最后一封邮件之后,而不是退出for语句代码后再次循环邮件并显示错误。所以我认为我需要申请一个出口来帮助你应用它。 – Supernova