palsop
asked on
Send a task to specific shared folder in Outlook from Access 2013
Hi,
Using Access & Outlook 2013. What I am trying to do is send a task to an exchange shared folder called P/O Tasks under the user admin1. I can get it to send to my default Tasks folder but that's as far as I can get, I've spent hours googleing to no avail, this is my VBA:
I don't know what the VBA is to select the correct P/O Tasks folder under the admin1 user
Any help greatly appreciated.
Thanks
Using Access & Outlook 2013. What I am trying to do is send a task to an exchange shared folder called P/O Tasks under the user admin1. I can get it to send to my default Tasks folder but that's as far as I can get, I've spent hours googleing to no avail, this is my VBA:
Private Sub createPOTask_Click()
Dim outLookApp As Outlook.Application
Dim OutlookTask As Outlook.TaskItem
Set outLookApp = CreateObject("outlook.application")
Set OutlookTask = outLookApp.CreateItem(olTaskItem)
With OutlookTask
.Subject = [qtysold] & " x " & [description] & " is required for " & Forms![or_ordermain_edit]![companyname] & " " & Forms![or_ordermain_edit]![customername] & " for Order No: " & Forms![or_ordermain_edit]![ordernumber]
.Body = ""
.DueDate = Forms![or_ordermain_edit]![collectiondate]
.Save
End With
MsgBox "Task have been sent to PO Tasks successfully.", vbInformation, "Set Task Confirmed" '
I don't know what the VBA is to select the correct P/O Tasks folder under the admin1 user
Any help greatly appreciated.
Thanks
ASKER
Hi,
Thanks for your reply to this...I get an error "Run-time error '424' Object required" which relates to Set NS = olApp.GetNamespace("MAPI")
Do you know what would cause that?
Thanks.
Thanks for your reply to this...I get an error "Run-time error '424' Object required" which relates to Set NS = olApp.GetNamespace("MAPI")
Do you know what would cause that?
Thanks.
ASKER
Got a bit further and got rid of the object required error. Now get an object could not be found error on this line: Set OutlookTask = SharedFolder.items.Add("P/ O Tasks")
Seems it cant find the P/O Tasks folder.
Dim outLookApp As Outlook.Application
Dim OutlookTask As Outlook.TaskItem
Dim NSpace As Object
Set outLookApp = CreateObject("outlook.application")
Set NSpace = outLookApp.GetNamespace("MAPI")
NSpace.Logon
Set Recip = NSpace.CreateRecipient("admin1")
Set SharedFolder = NSpace.GetSharedDefaultFolder(Recip, olFolderTasks)
Set OutlookTask = SharedFolder.items.Add("P/O Tasks")
With OutlookTask
.Subject = [qtysold] & " x " & [description] & " is required for " & Forms![or_ordermain_edit]![companyname] & " " & Forms![or_ordermain_edit]![customername] & " for Order No: " & Forms![or_ordermain_edit]![ordernumber]
.Body = ""
.DueDate = Forms![or_ordermain_edit]![collectiondate]
.Save
End With
MsgBox "Task have been sent to PO Tasks successfully.", vbInformation, "Set Task Confirmed"
Seems it cant find the P/O Tasks folder.
Try replacing "admin1" below with the email address for the admin1 user:
'Set Recip = NSpace.CreateRecipient("admin1")
Set Recip = NSpace.CreateRecipient("admin1@yourcompany.com")
ASKER
Hi,
That didnt work either - here is the latest version of the code:
That didnt work either - here is the latest version of the code:
Dim outLookApp As Outlook.Application
Dim OutlookTask As Outlook.TaskItem
Dim NS As Outlook.NameSpace
Set outLookApp = CreateObject("outlook.application")
Set NS = outLookApp.GetNamespace("MAPI")
NS.Logon
Set Recip = NS.CreateRecipient("admin1@yc.uk.com")
Set SharedFolder = NS.GetSharedDefaultFolder(Recip, olFolderTasks)
'MsgBox ([Recip] & [SharedFolder])
Set OutlookTask = SharedFolder.items.Add("PO Tasks")
With OutlookTask
.Subject = [qtysold] & " x " & [description] & " is required for " & Forms![or_ordermain_edit]![companyname] & " " & Forms![or_ordermain_edit]![customername] & " for Order No: " & Forms![or_ordermain_edit]![ordernumber]
.Body = ""
.DueDate = Forms![or_ordermain_edit]![collectiondate]
.Save
End With
MsgBox "Task have been sent to PO Tasks successfully.", vbInformation, "Set Task Confirmed"
Try this (changed items.Add to .CreateItem(olTaskItem):
Dim outLookApp As Outlook.Application
Dim OutlookTask As Outlook.TaskItem
Dim NS As Outlook.NameSpace
Set outLookApp = CreateObject("outlook.application")
Set NS = outLookApp.GetNamespace("MAPI")
NS.Logon
Set Recip = NS.CreateRecipient("admin1@yc.uk.com")
Set SharedFolder = NS.GetSharedDefaultFolder(Recip, olFolderTasks)
'MsgBox ([Recip] & [SharedFolder])
Set OutlookTask = SharedFolder.CreateItem(olTaskItem)
With OutlookTask
.Subject = [qtysold] & " x " & [description] & " is required for " & Forms![or_ordermain_edit]![companyname] & " " & Forms![or_ordermain_edit]![customername] & " for Order No: " & Forms![or_ordermain_edit]![ordernumber]
.Body = ""
.DueDate = Forms![or_ordermain_edit]![collectiondate]
.Save
End With
MsgBox "Task have been sent to PO Tasks successfully.", vbInformation, "Set Task Confirmed"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Because it works and other suggestions didnt
Open in new window