【问题标题】:VBA Access - Outlook cannot find name assigning a task through AccessVBA Access - Outlook 找不到通过 Access 分配任务的名称
【发布时间】:2020-07-13 15:41:51
【问题描述】:

我已成功编写代码以在 Outlook 中创建任务。我在 Private Sub OutlookTask_Click() 中使用了下面的代码来定义收件人,它也运行良好。但是,我需要在 Outlook 任务表单中添加一些自定义字段。我将代码更改为 Private Sub test1_Click() 中列出的代码。使用 .save 将任务分配给我自己可以正常工作。当我分配给其他人时,我收到错误 Outlook 找不到名称。发布的答案很好,只需将 MyItem 更改为 OlTask​​。

Private Sub OutlookTask_Click()
Dim OlApp As Outlook.Application
Dim OlTask As Outlook.TaskItem
Dim OlTaskProp As Outlook.UserProperty
Dim OlLocation As Object
Dim OlDelegate As Outlook.Recipient
Dim TName As String


Set OlApp = CreateObject("Outlook.Application")
Set OlTask = OlApp.CreateItem(olTaskItem)
Set OlTaskProp = OlLocation.UserProperties.Find("Mlocation")
TName = Me.Alias
'Set OlDelegate = OlTask.Recipients.Add(TName)

With OLTask
    .Subject = Me.Item
    .StartDate = Me.Start_Date
    .DueDate = Me.Due_Date
    .Status = TStatus
    .Importance = TPriority
    .ReminderSet = True
    .ReminderTime = Me.Due_Date - 3 & " 8:00AM"
    .Body = Me.Description
    .UserProperties("MLocation") = Me.Location


If Me.Alias = "Troy" Then
          .Save
        Else
         .Assign
         Dim myDelegate As Outlook.Recipient
         Set myDelegate = OlTask.Recipients.Add(TName)
         myDelegate.Resolve
    End If

    If myDelegate.Resolved Then
        .Send
    Else
        MsgBox "Name not Found"

    End If
MsgBox "Task Successful"
End Sub



Private Sub test1_Click()

Dim OlApp As Outlook.Application
Dim objFolder As MAPIFolder
Dim OLTask As Outlook.TaskItem
Dim OlItems As Outlook.Items
Dim OlDelegate As Outlook.Recipient
Dim TName As String
Dim TStatus As Integer
Dim TPriority As Integer

Set OlApp = CreateObject("Outlook.Application")
Set objFolder = OlApp.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks)
Set OlItems = objFolder.Items
Set OLTask = OlItems.Add("IPM.Task.TroyTask")
TName = Me.Alias
Set OlDelegate = OLTask.Recipients.Add(TName)


With OLTask
    .Subject = Me.Item
    .StartDate = Me.Start_Date
    .DueDate = Me.Due_Date
    .Status = TStatus
    .Importance = TPriority
    .ReminderSet = True
    .ReminderTime = Me.Due_Date - 3 & " 8:00AM"
    .Body = Me.Description
    .UserProperties("MLocation") = Me.Location


If Me.Alias = "Troy" Then
    .Save
    Else
        .Assign
        .Send
    End If
End With
MsgBox "Task Successful"
End Sub

【问题讨论】:

    标签: ms-access outlook vba


    【解决方案1】:

    您似乎在没有充分准备其内部结构的情况下提交委派任务,因为Assign() 后面紧跟着Send()

    If Me.Alias = "Troy" Then
        .Save
    Else
        .Assign
        .Send   ' problem
    End If
    

    在这种情况下,需要解析收件人。请参阅正在工作的example 中可见的任务委托名称的解析。我在这里没有测试就采用了它:

    If Me.Alias = "Troy" Then
        .Save
    Else
        .Assign
        Dim myDelegate As Outlook.Recipient             'added
        Set myDelegate = OlTask.Recipients.Add(TName)   'added
        myDelegate.Resolve                              'added
        If myDelegate.Resolved Then                     'added
            .Send
        Else                                            'added
            'report error here                          'added
        End If                                          'added
    End If
    

    Resolve() 调用可以在您的代码中更早,这只是示例中的一个说明。

    【讨论】:

    • 感谢您的建议。除了解决方案,我什么都试过了。奇怪的是,现在的错误与之前的“找不到收件人”相同,但它发生在 .Send 上,就好像它已解决一样。似乎有一些与 MAPI 文件夹相关并指向 OlTask​​s 文件夹的东西。
    • @TroyL - 也许您可以使用其他人可见的新代码来更新您的问题以帮助您
    • 您好,在编辑我的帖子时,我注意到我没有将 MyItem 更改为 OlTask​​。进行了更改,并且可以正常工作。感谢您的解决方案。
    • @TroyL – 我也修复了代码。很高兴找到缺少收件人并解决问题的罪魁祸首。如果以上是实际答案,也许您可​​以考虑将其标记为已接受,如tour 所示。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-17
    • 1970-01-01
    • 1970-01-01
    • 2013-10-15
    • 2021-05-11
    • 1970-01-01
    相关资源
    最近更新 更多