But yes, also try spikepl's suggestion:Try .Assign before doing recipients
Code:
' Create new task item
Set olTask = olApp.CreateItem(olTaskItem)
[COLOR="Blue"] olTask.Assign[/COLOR]
But yes, also try spikepl's suggestion:Try .Assign before doing recipients
' Create new task item
Set olTask = olApp.CreateItem(olTaskItem)
[COLOR="Blue"] olTask.Assign[/COLOR]
Dim olApp As Outlook.Application
Dim olNSpace As Outlook.Namespace
Dim olTask As Outlook.TaskItem
Dim olRecipient As Outlook.Recipient
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim intCount As Long
Set olApp = New Outlook.Application
Set olNSpace = olApp.GetNamespace("MAPI")
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SendTasks_qry", dbOpenSnapshot)
Do While Not rst.EOF
' Create new task item
Set olTask = olNSpace.Application.CreateItem(olTaskItem)
MsgBox olNSpace.CurrentUser
Private Sub SendTasks_Button_Click()
Dim olApp As Outlook.Application
Dim olNSpace As Outlook.NameSpace
Dim olTask As Outlook.TaskItem
Dim olRecipient As Outlook.Recipient
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim intCount As Long
Set olApp = New Outlook.Application
Set olNSpace = olApp.GetNamespace("MAPI")
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SendTasks_qry", dbOpenSnapshot)
Do While Not rst.EOF
' Create new task item
Set olTask = olNSpace.Application.CreateItem(olTaskItem)
MsgBox olNSpace.CurrentUser
' Add the delegate
strRecipient = rst!EMAIL.Value
olTask.Recipients.Add strRecipient
Set olRecipient = olTask.Recipients(1)
' Resolve the delegate and send
With olRecipient
.Resolve
If .Resolved Then
With olTask
.Assign
.Subject = rst!Subject & ": " & rst!NAME
.DueDate = rst!DueDate
.Importance = rst!Importance
.Save
.Display True
.Send
End With
Else
intCount = intCount + 1
End If
End With
rst.MoveNext
Loop
' Notify
If intCount = 0 Then
MsgBox "All tasks were sent successfully!" & _
vbNewLine & vbNewLine & _
"Sent to " & intCount & " recipient(s)", _
vbInformation + vbOKOnly, _
"Tasks sent"
ElseIf intCount <> rst.RecordCount Then
MsgBox "Some tasks were not sent" & _
vbNewLine & vbNewLine & _
"Couldn't resolve " & rst.RecordCount - intCount & " recipient(s)", _
vbExclamation + vbOKOnly, _
"Tasks not sent"
Else
MsgBox "Tasks not sent" & _
vbNewLine & vbNewLine & _
"Couldn't resolve any recipient", _
vbExclamation + vbOKOnly, _
"Tasks not sent"
End If
' Cleanup
Set olTask = Nothing
Set olApp = Nothing
Set rst = Nothing
Set dbs = Nothing
End Sub
Private Sub SendTasks_Button_Click()
Dim olApp As Outlook.Application
Dim olNSpace As Outlook.Namespace
Set olApp = New Outlook.Application
Set olNSpace = olApp.GetNamespace("MAPI")
With olNSpace
MsgBox "Is Online: " & CBool(olNSpace.Offline)
MsgBox "Conn mode: " & olNSpace.ExchangeConnectionMode
MsgBox "Mail Server: " & olNSpace.ExchangeMailboxServerName
[COLOR="Blue"] .Logon "", , True, True[/COLOR]
MsgBox "Is Online: " & CBool(olNSpace.Offline)
MsgBox "Conn mode: " & olNSpace.ExchangeConnectionMode
MsgBox "Mail Server: " & olNSpace.ExchangeMailboxServerName
End With
End Sub
I forgot to mention that you should try that with Outlook closed.
I missed this bit... the code I gave you works because I tested it on my machine, so it's nothing to do with whether it works or whether it's possible or not. There's just something that's preventing your recipients from being "manipulated" in code.EDIT:
I checked another forum topic that I read through before I saw that this person was able to use an email address... so it does appear to be possible!
http://www.access-programmers.co.uk/forums/showthread.php?t=79767
Public Sub TasksTest()
Dim olTask As Outlook.TaskItem
Dim olRecipient As Outlook.Recipient
' Create new task item
Set olTask = Application.CreateItem(olTaskItem)
' Add the delegate
Set olRecipient = olTask.Recipients.Add("[COLOR="Blue"]Email address here[/COLOR]")
End Sub
Private Sub SendTasks_Button_Click()
Dim olApp As Outlook.Application
Dim olNSpace As Outlook.Namespace
Dim olFold As Outlook.Folder
Dim olExplorer As Outlook.Explorer
Dim olTask As Outlook.TaskItem
Dim olRecipient As Outlook.Recipient
Set olApp = New Outlook.Application
Set olNSpace = olApp.GetNamespace("MAPI")
olNSpace.Folders("[COLOR="blue"]Email address here[/COLOR]").Folders("Inbox").Display
' olNSpace.GetDefaultFolder(olFolderInbox).Display
' Create new task item
Set olTask = olNSpace.Application.CreateItem(olTaskItem)
' Add the delegate
Set olRecipient = olTask.Recipients.Add("[COLOR="Blue"]Email address here[/COLOR]")
End Sub
Ha, don't pop the champagne yet!I have to admit... seeing Outlook popped up like that gave me hope again.
I've given this some thought and you have two options:
1. Write the function in Outlook and fetch your data from Access. You'll have to run the code from within Outlook.
2. Write the function in Outlook but attempt to call the function from Access.