I have a form set up so the user enters in a project. They fill in their own name as the requester. They can assign the project to either themself, or somebody else. When the project is assigned to themself, I want it to create a task in their outlook. When the project is assigned to somebody else, it should assign a task to that person, and send it through outlook. I can get it to send a task to somebody else, but cannot get it to create one in their own outlook if they assign a project to themself. I included the code I am using. It gives an error when assigned to themself - "Assign statement must be used before a task is sent." However, if I assign the task, and set the recipient the same as the origin, it says that you cannot send a task to yourself. Any ideas?
'Open and populate the recordset with required data
Set dbs = CurrentDb
Set rs1 = dbs.OpenRecordset("Select * FROM Ref_Employee WHERE Name = '" & Forms!EngWo!RequesterName.Value & "'"
Set rs2 = dbs.OpenRecordset("Select * FROM Ref_Employee WHERE Name = '" & Forms!EngWo!AssignedTo.Value & "'"
'Gather the information about the e-mail
email = rs2("Email"
origin = rs1("Email"
'Set up the body of the e-mail to add all fields
TxtBody = OrderDate & Chr(13) & Chr(13)
TxtBody = TxtBody & "Project: " & ProjectNumber & " - " & ProjectName & Chr(13)
TxtBody = TxtBody & "Name of Requester: " & RequesterName & Chr(13)
TxtBody = TxtBody & "Context of Test: " & TestContext & Chr(13) & Chr(13)
TxtBody = TxtBody & "Description of Work: " & DescriptionOfWork & Chr(13) & Chr(13)
TxtBody = TxtBody & "Assigned To: " & AssignedTo & Chr(13)
TxtBody = TxtBody & "Start Date: " & StartDate & Chr(13)
'Create instance of Outlook, and a task object
Set objOutlook = CreateObject("Outlook.application"
Set objTask = objOutlook.CreateItem(olTaskItem)
'Create and assign task ONLY IF requester is not assignee. Otherwise, create task for self
If Not email = origin Then
With objTask
.Assign
.Recipients.Add (email)
.Subject = "You have been assigned project #" & ProjectNumber & " - " & ProjectName & ", by " & origin & "!"
.Body = TxtBody
If Not IsNull(RequiredBy) Then
.DueDate = RequiredBy
End If
If Not IsNull(StartDate) Then
.StartDate = StartDate
End If
.Send
End With
Else
With objTask
' .Subject = "You have created project #" & ProjectNumber & " - " & ProjectName & "!"
.Body = TxtBody
If Not IsNull(RequiredBy) Then
.DueDate = RequiredBy
End If
If Not IsNull(StartDate) Then
.StartDate = StartDate
End If
.Send
End With
End If
Thanks in advance for all help and suggestions.
Jon
'Open and populate the recordset with required data
Set dbs = CurrentDb
Set rs1 = dbs.OpenRecordset("Select * FROM Ref_Employee WHERE Name = '" & Forms!EngWo!RequesterName.Value & "'"
Set rs2 = dbs.OpenRecordset("Select * FROM Ref_Employee WHERE Name = '" & Forms!EngWo!AssignedTo.Value & "'"
'Gather the information about the e-mail
email = rs2("Email"
origin = rs1("Email"
'Set up the body of the e-mail to add all fields
TxtBody = OrderDate & Chr(13) & Chr(13)
TxtBody = TxtBody & "Project: " & ProjectNumber & " - " & ProjectName & Chr(13)
TxtBody = TxtBody & "Name of Requester: " & RequesterName & Chr(13)
TxtBody = TxtBody & "Context of Test: " & TestContext & Chr(13) & Chr(13)
TxtBody = TxtBody & "Description of Work: " & DescriptionOfWork & Chr(13) & Chr(13)
TxtBody = TxtBody & "Assigned To: " & AssignedTo & Chr(13)
TxtBody = TxtBody & "Start Date: " & StartDate & Chr(13)
'Create instance of Outlook, and a task object
Set objOutlook = CreateObject("Outlook.application"
Set objTask = objOutlook.CreateItem(olTaskItem)
'Create and assign task ONLY IF requester is not assignee. Otherwise, create task for self
If Not email = origin Then
With objTask
.Assign
.Recipients.Add (email)
.Subject = "You have been assigned project #" & ProjectNumber & " - " & ProjectName & ", by " & origin & "!"
.Body = TxtBody
If Not IsNull(RequiredBy) Then
.DueDate = RequiredBy
End If
If Not IsNull(StartDate) Then
.StartDate = StartDate
End If
.Send
End With
Else
With objTask
' .Subject = "You have created project #" & ProjectNumber & " - " & ProjectName & "!"
.Body = TxtBody
If Not IsNull(RequiredBy) Then
.DueDate = RequiredBy
End If
If Not IsNull(StartDate) Then
.StartDate = StartDate
End If
.Send
End With
End If
Thanks in advance for all help and suggestions.
Jon