Web Development
4 replies
by p7ants
Alec,
Please excuse the brevity. Just cut and paste this into an Access Module. Let me know if more is needed. I am willing to explain as well. Send me an email if you wish.
Phil
Private myOlApp As Object
Private myNameSpace As Object
Private myFolder As Object
Private myItem As Object
Private boolCreate As Boolean
'
Public Function AddOLTask(snote As String, sSub As String, dStDt As Date) As Boolean
snote = snote & vbCrLf & "Added by Access"
On Error Resume Next
Set myOlApp = GetObject(, "Outlook.Application")
On Error GoTo CheckError
If myOlApp Is Nothing Then
Set myOlApp = CreateObject _
("Outlook.Application")
boolCreate = True
End If
Set myNameSpace = _
myOlApp.GetNamespace("MAPI")
Set myFolder = _
myNameSpace.GetDefaultFolder(13)
Set myItem = myOlApp.CreateItem(3)
With myItem
.StartDate = dateStDt
.Subject = sSub
.Body = snote
.Categories = "MyCategory"
.ReminderSet = False
.Save
End With
AddOLTask = True
Finish:
If Not myNameSpace Is Nothing Then _
Set myNameSpace = Nothing
If Not myFolder Is Nothing Then _
Set myFolder = Nothing
If Not myOlApp Is Nothing Then
If boolCreate Then
myOlApp.Quit
Set myOlApp = Nothing
End If
End If
Exit Function
CheckError:
AddOLTask = False
Select Case Err.Number
Case -2147352571
MsgBox "Date Error"
Case Else
MsgBox "Bad error" & Err.Number & " " _
& Err.Description
End Select
Resume Finish
End Function
Private Sub Command0_Click()
If AddOLTask("note", _
"A new task from Outlook", _
"4/1/01") Then
MsgBox "successful", _
vbOKOnly + vbInformation, _
"Outlook Task Addition"
Else
MsgBox "failed", _
vbOKOnly + vbCritical, _
"Outlook Task Addition"
End If
End Sub
by p7ants
by alec.austin
by alec.austin
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending