0

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
1
  • I think you need to set another error handler within the outlook task, as the error from outlook wouldn't get passed back. Commented Jun 15, 2017 at 16:01

1 Answer 1

1

DataErr and Response are arguments to the Form_Error-Event. They have no effect in error handling in general. In your procedure DataErr is simply an integer variable and will always have the value 0 unless you explicitly assign another value.

You need to check for Err.Number in the error handler to identify specific error conditions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.