访问vba:创建Outlook任务/如果为空则

时间:2017-06-09 19:03:20

标签: vba ms-access access-vba

我一直在尝试使用一个可以在Outlook上创建任务的按钮。 但是我还需要一个代码,当其中一个必填字段为空时,它会显示一个消息框,而不是看到Access本身生成的错误消息。

正在成功创建Outlook任务,但在设置提醒时间时,NULL字段(dueBY)是问题。

Private Sub Command15_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblActions")

Set outLookApp = CreateObject("outlook.application")
Set OutlookTask = outLookApp.CreateItem(olTaskItem)

With OutlookTask
.Subject = "Action Due Date: " & Me.dueBy & " for Contract ID " & Me.contractID
.Body = "Due date for Action: < " & Me.actionNote & " > is " & Me.dueBy & "."
.ReminderSet = True
If Me.dueBy = "" Then
MsgBox "No set due date"
Else: OutlookTask.ReminderTime = Me.dueBy 
End If
.Save
End With

MsgBox "Action Task has been set in Outlook successfully."
End Sub

1 个答案:

答案 0 :(得分:1)

您已经有代码检查dueBy,您只需要在消息框后面的行上Exit Sub