Help on Code - Create "Normal" Outlook Task from Access

S

Sunflower

I used code to create an Outlook task from Access...

Creating a task manually in Outlook shows a tick box, date field, etc
but a task
created using this code does not seem to have those controls. The
whole task form looks pretty different so I am guessing there is
something else that needs to be done to show it like a 'normal' task
form.

My code in Access

Public Function AssignTask()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.Outlook.TaskRequestItem
Dim myDelegate As Outlook.Recipient
'Information from subform
Dim strReciprient As String, strResponsibleParty As String 'These are
the same person
Dim strProject As String 'ActionDescription
Dim strFacility As String
Dim strFrequency As String
Dim strDueDate As String
Dim frm As Form
Dim sfN As Form 'Program Notification SubForm

Set frm = Forms!frmMainEntry.Form
Set sfN = frm.[fctlNotifications].Form
If sfN.[ProgramID] = sfN.[txtID] Then

strProject = sfN.ProgramDescription
strFacility = sfN.Facility
strDueDate = sfN.DueDate
strFrequency = sfN.FrequencyOfService
strReciprient = sfN.EmailAddress
strResponsibleParty = sfN.ResponsibleParty
strSender = frm!txtWelcome
Else
Exit Function
End If

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olTaskItem)

myItem.Assign
Set myDelegate = myItem.Recipients.Add(strReciprient)
myDelegate.Resolve
If myDelegate.Resolved Then
myItem.Subject = "Notification Of Compliance Requirement"
myItem.Body = vbCrLf & vbCrLf & vbCrLf & _
"To: " & strResponsibleParty & vbCrLf & vbCrLf & vbCrLf & _
"This is to notify you that the requirement for " & strProject & " at
the " & _
strFacility & " is due on " & strDueDate & "." & vbCrLf & _
strProject & " is required " & strFrequency & "." & vbCrLf & vbCrLf &
vbCrLf & _
"Keep On Track With Safety" & vbCrLf & strSender
myItem.DueDate = strDueDate
myItem.ReminderTime = DateAdd("ww", -1, strDueDate) 'Remind 1 Week
before Due Date.
'myItem.Display
myItem.Importance = (olImportanceHigh)
myItem.Send
End If
End Function


Any and all help greatly appreciated
 
S

Sunflower

I used code to create an Outlook task from Access...

Creating a task manually in Outlook shows a tick box, date field, etc
but a task
created using this code does not seem to have those controls. The
whole task form looks pretty different so I am guessing there is
something else that needs to be done to show it like a 'normal' task
form.

My code in Access

Public Function AssignTask()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.Outlook.TaskRequestItem
Dim myDelegate As Outlook.Recipient
'Information from subform
Dim strReciprient As String, strResponsibleParty As String 'These are
the same person
Dim strProject As String 'ActionDescription
Dim strFacility As String
Dim strFrequency As String
Dim strDueDate As String
Dim frm As Form
Dim sfN As Form 'Program Notification SubForm

Set frm = Forms!frmMainEntry.Form
Set sfN = frm.[fctlNotifications].Form
If sfN.[ProgramID] = sfN.[txtID] Then

strProject = sfN.ProgramDescription
strFacility = sfN.Facility
strDueDate = sfN.DueDate
strFrequency = sfN.FrequencyOfService
strReciprient = sfN.EmailAddress
strResponsibleParty = sfN.ResponsibleParty
strSender = frm!txtWelcome
Else
Exit Function
End If

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olTaskItem)

myItem.Assign
Set myDelegate = myItem.Recipients.Add(strReciprient)
myDelegate.Resolve
If myDelegate.Resolved Then
myItem.Subject = "Notification Of Compliance Requirement"
myItem.Body = vbCrLf & vbCrLf & vbCrLf & _
"To: " & strResponsibleParty & vbCrLf & vbCrLf & vbCrLf & _
"This is to notify you that the requirement for " & strProject & " at
the " & _
strFacility & " is due on " & strDueDate & "." & vbCrLf & _
strProject & " is required " & strFrequency & "." & vbCrLf & vbCrLf &
vbCrLf & _
"Keep On Track With Safety" & vbCrLf & strSender
myItem.DueDate = strDueDate
myItem.ReminderTime = DateAdd("ww", -1, strDueDate) 'Remind 1 Week
before Due Date.
'myItem.Display
myItem.Importance = (olImportanceHigh)
myItem.Send
End If
End Function

Any and all help greatly appreciated

Posted wrong code in previous upload...

Bere is the correct Access code to create Outlook Task:

Private Sub cmdSend_Click()
Dim NowDate As Date
Dim DateEnd As Date
Dim Task As Object

Set Task = Outlook.CreateItem(olTaskItem)
NowDate = Now()

Task.Subject = "WO#" & Me.[WOID] & " - " & Me.[ProjectName].Value
Task.Body = "Requester: " & Me.[Requestor] & vbCrLf & vbCrLf & _
" -------------------- " & vbCrLf & vbCrLf & _
Me.[Comment] & vbCrLf & vbCrLf & _
" -------------------- " & vbCrLf & vbCrLf & _
Me.[Filepath].Value
Task.Assign
Task.DueDate = Me.[DateDue].Value
Task.STARTDATE = Me.[DateDue].Value - 5
Task.ReminderSet = True

Task.Importance = (olImportanceHigh)

Task.Save

End Sub
 
S

Sunflower

I used code to create an Outlook task from Access...

Creating a task manually in Outlook shows a tick box, date field, etc
but a task
created using this code does not seem to have those controls. The
whole task form looks pretty different so I am guessing there is
something else that needs to be done to show it like a 'normal' task
form.

My code in Access

Public Function AssignTask()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.Outlook.TaskRequestItem
Dim myDelegate As Outlook.Recipient
'Information from subform
Dim strReciprient As String, strResponsibleParty As String 'These are
the same person
Dim strProject As String 'ActionDescription
Dim strFacility As String
Dim strFrequency As String
Dim strDueDate As String
Dim frm As Form
Dim sfN As Form 'Program Notification SubForm

Set frm = Forms!frmMainEntry.Form
Set sfN = frm.[fctlNotifications].Form
If sfN.[ProgramID] = sfN.[txtID] Then

strProject = sfN.ProgramDescription
strFacility = sfN.Facility
strDueDate = sfN.DueDate
strFrequency = sfN.FrequencyOfService
strReciprient = sfN.EmailAddress
strResponsibleParty = sfN.ResponsibleParty
strSender = frm!txtWelcome
Else
Exit Function
End If

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olTaskItem)

myItem.Assign
Set myDelegate = myItem.Recipients.Add(strReciprient)
myDelegate.Resolve
If myDelegate.Resolved Then
myItem.Subject = "Notification Of Compliance Requirement"
myItem.Body = vbCrLf & vbCrLf & vbCrLf & _
"To: " & strResponsibleParty & vbCrLf & vbCrLf & vbCrLf & _
"This is to notify you that the requirement for " & strProject & " at
the " & _
strFacility & " is due on " & strDueDate & "." & vbCrLf & _
strProject & " is required " & strFrequency & "." & vbCrLf & vbCrLf &
vbCrLf & _
"Keep On Track With Safety" & vbCrLf & strSender
myItem.DueDate = strDueDate
myItem.ReminderTime = DateAdd("ww", -1, strDueDate) 'Remind 1 Week
before Due Date.
'myItem.Display
myItem.Importance = (olImportanceHigh)
myItem.Send
End If
End Function

Any and all help greatly appreciated

I used code to create a Outlook task from Access...

Creating a task manually in Outlook shows a tick box, date field, etc
but a task
created using this code does not seem to have those controls. The
whole task form looks pretty different so I am guessing there is
something else that needs to be done to show it like a 'normal' task
form.

My code in Access
__________________________________________________________

Private Sub cmdSend_Click()
Dim NowDate As Date
Dim DateEnd As Date
Dim Task As Object

Set Task = Outlook.CreateItem(olTaskItem)
NowDate = Now()

Task.Subject = "WO#" & Me.[WOID] & " - " & Me.[ProjectName].Value
Task.Body = "Requester: " & Me.[Requestor] & vbCrLf & vbCrLf & _
" -------------------- " & vbCrLf & vbCrLf & _
Me.[Comment] & vbCrLf & vbCrLf & _
" -------------------- " & vbCrLf & vbCrLf & _
Me.[Filepath].Value
Task.Assign
Task.DueDate = Me.[DateDue].Value
Task.STARTDATE = Me.[DateDue].Value - 5
Task.ReminderSet = True

Task.Importance = (olImportanceHigh)

Task.Save

End Sub
________________________________________________________


Any and all help greatly appreciated
 
S

Sue Mosher [MVP]

Do you have a reference to the Outlook Library in your Access project? If
not, the olTaskItem constant will be treated as an undeclared variable rather
than a constant. Add an Option Explicit to your module's declarations section
to avoid that kind of problem.

If that's not the issue, we'll need to know what you do see. We only know
what you don't see.

FYI, for macro questions, please use the newsgroup specifically for general
Outlook programming issues "down the hall" at
microsoft.public.outlook.program_vba or, via web interface, at
http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.outlook.program_vba
.. I have crossposted my reply to that group and will look there for any
further questions you might have, not in the microsoft.public.outlook General
Questions group.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54



Sunflower said:
I used code to create an Outlook task from Access...

Creating a task manually in Outlook shows a tick box, date field, etc
but a task
created using this code does not seem to have those controls. The
whole task form looks pretty different so I am guessing there is
something else that needs to be done to show it like a 'normal' task
form.

My code in Access

Public Function AssignTask()
Dim myOlApp As New Outlook.Application
Dim myItem As Outlook.Outlook.TaskRequestItem
Dim myDelegate As Outlook.Recipient
'Information from subform
Dim strReciprient As String, strResponsibleParty As String 'These are
the same person
Dim strProject As String 'ActionDescription
Dim strFacility As String
Dim strFrequency As String
Dim strDueDate As String
Dim frm As Form
Dim sfN As Form 'Program Notification SubForm

Set frm = Forms!frmMainEntry.Form
Set sfN = frm.[fctlNotifications].Form
If sfN.[ProgramID] = sfN.[txtID] Then

strProject = sfN.ProgramDescription
strFacility = sfN.Facility
strDueDate = sfN.DueDate
strFrequency = sfN.FrequencyOfService
strReciprient = sfN.EmailAddress
strResponsibleParty = sfN.ResponsibleParty
strSender = frm!txtWelcome
Else
Exit Function
End If

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(olTaskItem)

myItem.Assign
Set myDelegate = myItem.Recipients.Add(strReciprient)
myDelegate.Resolve
If myDelegate.Resolved Then
myItem.Subject = "Notification Of Compliance Requirement"
myItem.Body = vbCrLf & vbCrLf & vbCrLf & _
"To: " & strResponsibleParty & vbCrLf & vbCrLf & vbCrLf & _
"This is to notify you that the requirement for " & strProject & " at
the " & _
strFacility & " is due on " & strDueDate & "." & vbCrLf & _
strProject & " is required " & strFrequency & "." & vbCrLf & vbCrLf &
vbCrLf & _
"Keep On Track With Safety" & vbCrLf & strSender
myItem.DueDate = strDueDate
myItem.ReminderTime = DateAdd("ww", -1, strDueDate) 'Remind 1 Week
before Due Date.
'myItem.Display
myItem.Importance = (olImportanceHigh)
myItem.Send
End If
End Function


Any and all help greatly appreciated
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top