# VBA - Create Outlook Task, add record, and clear fields



## jtdenniston (Feb 16, 2008)

The following Code will create an outlook task for me, however, it will not create the record because the fields are getting cleared before the record is saved. Thus, not saving a record because the fields are empty. But my clear value code is AFTER the save record! I have to do an acNewRec because if I do a acNext, I get an error 'Cannot go to that specified record'. Can someone please help?

H

```
Sub Command12_Click()

    If chkReminder.Value = True Then
      Dim outobj As Outlook.Application
      Dim outtask As Outlook.TaskItem
      'Dim objApptOccur As TaskItem
      Set outobj = CreateObject("outlook.application")
      Set outtask = outobj.CreateItem(olTaskItem)
      With outtask
      outtask.DueDate = Follow_Up_Date
      .subject = "Follow Up with" & " " & [Forms]![frmContact Details].[First_Name] & " " & [Forms]![frmContact Details].[Last_Name]
      .Body = Me.General_Discussion
      '.Assign =
      outtask.Display
      End With
      ' Release the Outlook object variable.
      Set outobj = Nothing
      Set outtask = Nothing
      DoCmd.GoToRecord , , acNewRec
      DoCmd.Save
      Me.Refresh
    Else
      DoCmd.GoToRecord , , acNewRec
      Me.Refresh
      Me.Undo
      [Amount of Transaction].SetFocus
  End If
      Me.Amount_of_Transaction.Value = Null
      Me.General_Discussion.Value = Null
      Me.Follow_Up_Date.Value = Null
      [Amount of Transaction].SetFocus
End Sub
```


----------



## jtdenniston (Feb 16, 2008)

Excuse me, I apologize. CORRECTION: The records save, the fields DO clear, however, it will only save the most recent record saved.


----------

