Error 438 when sending Outlook calendar invite from within Access

  • Thread starter KFox via AccessMonster.com
  • Start date
K

KFox via AccessMonster.com

I followed the instructions posted here on how to set this up.

http://support.microsoft.com/default.aspx?scid=kb;en-us;160502

I'm needing to generate a calendar invite from within Access, populating the
fields with values I have in an Access table. This code worked great until I
added a recipient field, as I need the recipient to be populated by the
values in my table (MESSAGE_TO), and not just put the calendar invite on my
own personal Outlook calendar

Recipient = Me!MESSAGE_TO

Now when I click the button on my form to generate/send the invite I receive
the error, "438 Object doesn't support this property or method". I'm
guessing it has something to do with my reference library, but I'm not sure
what I need to add. I'm using Office 2003.

If I remove this .Recipient line from my code, I can get the calendar invite
to post on my own calendar, but that's not what I need to have happen.

Please advise.

Best Regards,
Kellie
 
G

Graham Mandeno

Hi Kellie

Outlook is telling you, quite rightly, that the AppointmentItem object does
not have a property or method named "Recipient".

What you need to do is get a reference to the user's default calendar folder
using the GetSharedDefaultFolder method, and then create the appointment in
that folder.

Something like this:

Dim olkApp As Outlook.Application
Dim olkNsp As Outlook.NameSpace
Dim olkCalendar As Outlook.MAPIFolder
Dim olkUser As Outlook.Recipient
Dim olkAppt As Outlook.AppointmentItem
Dim sUser As String
On Error GoTo ProcErr
sUser = Me!MESSAGE_TO
Set olkApp = CreateObject("Outlook.Application")
Set olkNsp = olkApp.GetNamespace("MAPI")
Set olkUser = olkNsp.CreateRecipient(sUser)
If Not olkUser.Resolve Then
MsgBox "User '" & sUser & "' not found"
GoTo ProcEnd
End If
Set olkCalendar = olkNsp.GetSharedDefaultFolder(olkUser, olFolderCalendar)
If olkCalendar Is Nothing Then
MsgBox sUser & "'s calendar cannot be accessed"
GoTo ProcEnd
End If
Set olkAppt = olkCalendar.Items.Add(olAppointmentItem)
If olkAppt Is Nothing Then
MsgBox "Cannot create new appointment"
GoTo ProcEnd
End If
With olkAppt
.Subject = <whatever>
.Start = <date and time>
' set other properties as required...
.Save
End With
ProcEnd:
Set olkAppt = Nothing
Set olkCalendar = Nothing
Set olkUser = Nothing
Set olkNsp = Nothing
Set olkApp = Nothing
Exit Function
ProcErr:
MsgBox Err.Description
Resume ProcEnd
 
K

KFox via AccessMonster.com

Thank you Graham!

I'm not very proficient at writing code, but I copied to the best of my
ability your code into what I had and compiled/corrected and I received no
errors; however, when I run the form I receive the error, "Object does not
support this property or method." Here's my code:


Private Sub AddAppt_Click()
On Error GoTo AddAppt_Err
On Error GoTo ProcErr
' Save record first to be sure required fields are filled.
DoCmd.RunCommand acCmdSaveRecord
' Exit the procedure if appointment has been added to Outlook.
If Me!AddedToOutlook = True Then
MsgBox "This appointment already added to Microsoft Outlook"
Exit Sub
' Add a new appointment.
Else
Dim olkApp As Outlook.Application
Dim olkNsp As Outlook.NameSpace
Dim olkCalendar As Outlook.MAPIFolder
Dim olkUser As Outlook.Recipient
Dim olkAppt As Outlook.AppointmentItem
Dim sUser As String

On Error GoTo ProcErr
sUser = Me!MESSAGE_TO
Set olkApp = CreateObject("Outlook.Application")
Set olkNsp = olkApp.GetNamespace("MAPI")
Set olkUser = olkNsp.CreateRecipient(sUser)
If Not olkUser.Resolve Then
MsgBox "User '" & sUser & "' not found"
GoTo ProcEnd
End If

Set olkCalendar = olkNsp.GetSharedDefaultFolder(olkUser, olFolderCalendar)

If olkCalendar Is Nothing Then
MsgBox sUser & "'s calendar cannot be accessed"
GoTo ProcEnd
End If

Set olkAppt = olkCalendar.Items.Add(olAppointmentItem)
If olkAppt Is Nothing Then
MsgBox "Cannot create new appointment"
GoTo ProcEnd
End If

With olkAppt
.Start = Me!ApptDate & " " & Me!ApptTime
.Duration = Me!ApptLength
.Subject = Me!EVENT
.Recipient = Me!MESSAGE_TO
If Not IsNull(Me!ApptNotes) Then .Body = Me!Company
If Not IsNull(Me!ApptLocation) Then .Location = _
Me!ApptLocation
If Me!ApptReminder Then
.ReminderMinutesBeforeStart = Me!ReminderMinutes
.ReminderSet = True
.Save
End If
End With
ProcEnd:
Set olkAppt = Nothing
Set olkCalendar = Nothing
Set olkUser = Nothing
Set olkNsp = Nothing
Set olkApp = Nothing

End If
' Release the Outlook object variable.
Set outobj = Nothing
' Set the AddedToOutlook flag, save the record, display a message.
Me!AddedToOutlook = True
DoCmd.RunCommand acCmdSaveRecord
MsgBox "Appointment Added!"
Exit Sub
Resume ProcEnd
AddAppt_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
ProcErr:
MsgBox Err.Description
Exit Sub
End Sub
 
G

Graham Mandeno

Hi Kellie

Do you know which line is raising the error? If not, then comment out the
"On Error GoTo" line and run it again. The code should stop at the
offending line.

There are a couple of other things I would suggest to tidy it up, but I'm
about to go out to a meeting so we'll address those later when you tell me
where the error is happening.
 
K

KFox via AccessMonster.com

Again, thank you Graham!! That was a brilliant idea and I resolved the issue
with the error-- I had to remove the .Recipient = Me!MESSAGE_TO line.
Unfortunately, the form is not sending any meeting/calendar requests now--
even ones to myself. 1) One of the fields on my form contains the names (e-
mail addresses) of who the meeting invite should go to, I receive an error if
more then one name is in this field-- I've been separating the e-mail
addresses with a semi-colon. The error is "User [e-mail address 1] and [e-
mail address 2] not found." After I click "OK" to this error, I get the
confirmation message that the meeting was added-- eventhough it wasn't. 2)
Since adding your code, even if only my e-mail address is on the form, I
receive a confirmation message that the appointment was added, yet it doesn't
appear on my calendar. 3) This same problem occurs if someone else's name
is in this field, besides my own, I receive the confirmation message that the
appointment was added-- yet when I checked with my co-worker, she has not
received an e-mail regarding the meeting request, nor is the meeting showing
up on her calendar. I suspect if I can resolve 1 and 2, 3 will be resolved
too. (?)

Any ideas?

Thanks!
Kellie
 
G

Graham Mandeno

Hi Kellie

Ah yes - I didn't look closely enough to notice you had not removed that
line :)

Please just clarify for me what you want to do here: Do you want to (a)
create appointment items in the calendars of the user (or users) who are
listed in the MESSAGE_TO field, or (b) create an appointment item in YOUR
OWN calendar, and then send meeting invitations to the user(s) listed in
MESSAGE_TO?
 
K

KFox via AccessMonster.com

My goal is (a). Ideally, I just need calendar invites to go out-- so the
recipient is aware that these appointments are being sent out and they are
responsible for clicking on "Accept" to add the appointment to their calendar.


Kellie
 
K

KFox via AccessMonster.com

Graham? I hope you haven't given up on me. I'm waiting with bated breath
for what to try next. =-)

Kellie
 
G

Graham Mandeno

Hi Kellie

I'm very sorry I went incommunicado - we've had a long holiday weekend here
and I've been away.

OK, so the approach for (b) is a bit different. I am by no means an expert
on Outlook, but from what I can tell, you need to create the AppointmentItem
in your OWN calendar, and then attach one or more Recipient objects to its
Recipients collection. Then, after saving the AppointmentItem, you do a
Sent to issue the invitations.

Later today I might have time to write and test some sample code for you, if
this is not enough to get you going.
 
K

KFox via AccessMonster.com

Phew, I'm glad you didn't give up on me. :)

I wanted to make sure you were clear that I'm needing approach (a), not (b).
I need to create appointment items in the calendars of the user (or users)
who are
listed in the MESSAGE_TO field.

I'd appreciate any help you could provide at this point. I'm at a loss.

Kellie
 
G

Graham Mandeno

Hi Kellie

No, I think you really do mean approach (b), not (a).

If I understand correctly, the mechanism for the "Invite Attendees" feature
in Outlook is that you, as the meeting organiser, create an AppointmentItem
in your own calendar, then you add attendees to the "invite" list, and this
sends each invitee a *copy* of the AppointmentItem by email. If the invitee
accepts the invitation, Outlook creates the appointment in their calendar
*at their end*.

The way you are trying to do it (a) is very limited, because you can only
create appointments in calendars which are on your own Exchange Server, and
to which you have write access.

If you use approach (b), you can invite attendees from other organisations,
simply by knowing their email addresses.

Before I write and test some sample code, am I on the right track?
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand
 
K

KFox via AccessMonster.com

Yes, you are correct. I hadn't thought of it in that detail before, but yes,
that's what I'm trying to do.

However, before you go through any more work, I think I might've found some
code that will do what I need.

Kellie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top