Link to home
Start Free TrialLog in
Avatar of palsop
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:

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" '

Open in new window


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
Avatar of Russell Fox
Russell Fox
Flag of United States of America image

I'm just looking at this page to tweak your case into this:
Private Sub createPOTask_Click()
Dim outLookApp As Outlook.Application
Dim OutlookTask As Outlook.TaskItem

Set outLookApp = CreateObject("outlook.application")
'----------------------------------------------------
Set ns = olApp.GetNamespace("MAPI") 
ns.Logon 
Set Recip = ns.CreateRecipient("admin1") 
Set SharedFolder = ns.GetSharedDefaultFolder(Recip, olFolderTasks) 
'----------------------------------------------------
'Set OutlookTask = outLookApp.CreateItem(olTaskItem)
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" '

Open in new window

Avatar of palsop
palsop

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.
Avatar of palsop

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")
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"

Open in new window


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")

Open in new window

Avatar of palsop

ASKER

Hi,

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"

Open in new window

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"

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of palsop
palsop

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of palsop

ASKER

Because it works and other suggestions didnt