Hi all, I have some code that I set up for sending tasks and appointments to Outlook that worked fine with Early Binding, and I'm now trying to convert this to Late Binding for compatibility between different office versions.
Here's the current code:
Code:
Private Function isAppThere(appName) As BooleanOn Error Resume Next
Dim objApp As Object
isAppThere = True
Set objApp = GetObject(, appName)
If Err.Number <> 0 Then isAppThere = False
End Function
Private Sub cmdSendToOutlook_Click()
On Error GoTo SendToOutlook_Err
' Save Record to be sure that required fields are filled
If Me.Dirty Then Me.Dirty = False
Dim outobj As Object
If isAppThere("Outlook.Application") = False Then
Set outobj = CreateObject("Outlook.Application")
Else
Set outobj = GetObject(, "Outlook.Application")
End If
' Determine whether we're adding to Calendar or Tasks
If Me.ActivityType = "Appointment" Then
Dim outappt As Object
Set outappt = outobj.CreateItem(1)
With outappt
.Start = Me.ActivityDate & " " & Me.ActivityTime
.Duration = 60
.Subject = Me.ActivityTitle
.Body = Nz(Me.ActivityDetails, vbNullString)
.ReminderMinutesBeforeStart = 60
.ReminderSet = True
.Save
End With
Set outappt = Nothing
Else
Dim outtask As Object
Set outtask = outobj.CreateItem(3)
With outtask
.Subject = Me.ActivityTitle
.Body = Nz(Me.ActivityDetails, vbNullString)
.DueDate = Me.ActivityDate
.Save
End With
Set outtask = Nothing
End If
' Release Outlook object variable
Set outobj = Nothing
' Save Record and display message
If Me.Dirty Then Me.Dirty = False
MsgBox "Sent to Outlook!"
Exit Sub
SendToOutlook_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
Exit Sub
End Sub
When I create the appointment and click my button, I get the following error:
Code:
Error - 2147417851
Method 'Subject' of object '_AppointmentItem' failed
Googling this error shows others with similar problems, but they either are unresolved or their solutions don't fix my problem...
Any ideas on what I did wrong? This code appears to be pretty identical to all of the examples I can find when googling Outlook Late Binding...