Add Contact Link for Appointment Item using Links Collection

K

kbrad

I am trying to add a Contact link to an appointment item using the Links collection as previously advised but am lost. My code (see below) adds an appointment item from an Access input form - no problem but I want to add the Contact link in addition to the basic appointment fields. Can anyone help with the code to do this
This code as it stands works so I have included this so you can see what I'm trying to do - I've removed all my failed attempts at including a Contact

Private Sub AddApp_Click(
On Error GoTo AddApp_Er

DoCmd.RunCommand acCmdSaveRecor

' Exit the procedure if appointment has been added to Outlook
If Me!AddedToOutlook = True The
MsgBox "This appointment already added to Microsoft Outlook
Exit Su
' Add a new appointment
Els

Dim outobj As Outlook.Applicatio
Dim outappt As Outlook.AppointmentIte

Set outobj = CreateObject("outlook.application"
Set outappt = outobj.CreateItem(olAppointmentItem

With outapp
.Start = Me!ApptDate & " " & Me!ApptTim
.Duration = Me!ApptLengt
.Subject = Me!App
If Not IsNull(Me!ApptNotes) Then .Body = Me!ApptNote
If Not IsNull(Me!ApptLocation) Then .Location =
Me!ApptLocatio
If Me!ApptReminder The
.ReminderMinutesBeforeStart = Me!ReminderMinute
.ReminderSet = Tru
End I
.Sav
End Wit

End I
' Release the Outlook object variable
Set outobj = Nothin
' Set the AddedToOutlook flag, save the record, display a message
Me!AddedToOutlook = Tru
DoCmd.RunCommand acCmdSaveRecor
MsgBox "Appointment Added!
Exit Su
AddApp_Err
MsgBox "Error " & Err.Number & vbCrLf & Err.Descriptio
Exit Su
End Sub
 
S

Sue Mosher [MVP-Outlook]

I don't see any reference in your code below to the particular contact that
you want to add. You have to return that first using any of the methods
available for creating a new contact or returning an existing one. Then it's
just:

outappt.Links.Add objContact

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



kbrad said:
I am trying to add a Contact link to an appointment item using the Links
collection as previously advised but am lost. My code (see below) adds an
appointment item from an Access input form - no problem but I want to add
the Contact link in addition to the basic appointment fields. Can anyone
help with the code to do this?
This code as it stands works so I have included this so you can see what
I'm trying to do - I've removed all my failed attempts at including a
Contact.
 
K

kbrad

I have a field on my Access form which holds the name (first and surname) of a previously added Contact, which is also in my Outlook Contacts folder. I want to add this with the Appointment Date, Time etc as I create the Appointment in Outlook but don't know how to set up the code to do it. I guess that I am missing quite a bit from the early part of the code where I am declaring variables etc
How do I set up the objContact in your last suggestion from ContName field on my form?
I have searched in all sorts of places for more help on this but can't find any. Can you help

----- Sue Mosher [MVP-Outlook] wrote: ----

I don't see any reference in your code below to the particular contact tha
you want to add. You have to return that first using any of the method
available for creating a new contact or returning an existing one. Then it'
just

outappt.Links.Add objContac

--
Sue Mosher, Outlook MV
Author o
Microsoft Outlook Programming - Jumpstart fo
Administrators, Power Users, and Developer
http://www.outlookcode.com/jumpstart.asp


kbrad said:
I am trying to add a Contact link to an appointment item using the Link
collection as previously advised but am lost. My code (see below) adds a
appointment item from an Access input form - no problem but I want to ad
the Contact link in addition to the basic appointment fields. Can anyon
help with the code to do this
This code as it stands works so I have included this so you can see wha
I'm trying to do - I've removed all my failed attempts at including
Contact
 
S

Sue Mosher [MVP-Outlook]

You would have to use the MAPIFolder.Items.Find method to search for the
contact using the first and last name. A better approach might be to store
the contact's EntryID in the database table. With that, you can look it up
directly using the Namespace.GetItemFromID method.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



kbrad said:
I have a field on my Access form which holds the name (first and surname)
of a previously added Contact, which is also in my Outlook Contacts folder.
I want to add this with the Appointment Date, Time etc as I create the
Appointment in Outlook but don't know how to set up the code to do it. I
guess that I am missing quite a bit from the early part of the code where I
am declaring variables etc.
How do I set up the objContact in your last suggestion from ContName field on my form?
I have searched in all sorts of places for more help on this but can't find any. Can you help?

----- Sue Mosher [MVP-Outlook] wrote: -----

I don't see any reference in your code below to the particular contact that
you want to add. You have to return that first using any of the methods
available for creating a new contact or returning an existing one. Then it's
just:

outappt.Links.Add objContact

kbrad said:
I am trying to add a Contact link to an appointment item using the
Links
collection as previously advised but am lost. My code (see below) adds an
appointment item from an Access input form - no problem but I want to add
the Contact link in addition to the basic appointment fields. Can anyone
help with the code to do this?
This code as it stands works so I have included this so you can see
what
I'm trying to do - I've removed all my failed attempts at including a
Contact.
Outlook.
If Me!AddedToOutlook = True Then
MsgBox "This appointment already added to Microsoft Outlook"
Exit Sub
' Add a new appointment.
Else
Dim outappt As Outlook.AppointmentItem
Set outappt = outobj.CreateItem(olAppointmentItem)
.Start = Me!ApptDate & " " & Me!ApptTime
.Duration = Me!ApptLength
.Subject = Me!Appt
If Not IsNull(Me!ApptNotes) Then .Body = Me!ApptNotes
If Not IsNull(Me!ApptLocation) Then .Location = _
Me!ApptLocation
If Me!ApptReminder Then
.ReminderMinutesBeforeStart = Me!ReminderMinutes
.ReminderSet = True
End If
.Save
End With
' 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
AddApp_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
Exit Sub
End Sub
 

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