I've been trying to set a outlook task item through Access and replace a runtime error 440 with a custom message. This error popped when a certain field (me.dueBy) was empty. Currently the code I have is successful with creating a task for records with dueBy data, but when I click on the button for a record with no due date, then nothing happens. No message box, no error, nothing.
I just need a message box telling me that I require a due date to set a task when that field is empty.
Private Sub Command15_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim DataErr As Integer
Dim Response As Integer
On Error GoTo err_handler
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
.ReminderTime = Me.dueBy + TimeValue("8:00:00 AM")
.Save
End With
MsgBox "Action Task has been set in Outlook successfully."
exit_err_handler: Exit Sub
err_handler:
If DataErr = 440 Then
Response = acDataErrContinue
MsgBox "Due date is required.", vbOKOnly, "Due date Error"
End If
Resume exit_err_handler
Set rs = Nothing
Set db = Nothing
End Sub