I solved it like this. The user wants to put the
information into a specific folder. The Find method does
work on the Email1Address property.
Private Sub cmdOutlook_Click()
On Error GoTo EH
Dim objContactItem As ContactItem
Dim objFolder As Outlook.MAPIFolder
Dim objFolderLevel1 As Outlook.MAPIFolder
Set olkApp = New Outlook.Application
Set olkNameSpace = olkApp.GetNamespace("MAPI")
Set objFolderLevel1 = olkNameSpace.GetDefaultFolder
(olFolderContacts)
Set objFolder = objFolderLevel1.Folders("EventContacts")
If IsNull(Me.Adressedemessagerie) Then
Set objContactItem = objFolder.Items.Find
("[Categories] =""" & "EventsContact" & CStr(Me.ID) & """")
Else
Set objContactItem = objFolder.Items.Find
("[Email1Address] =""" & Me.Adressedemessagerie & """")
End If
If objContactItem Is Nothing Then
'-- Create an Outlook contact entry
'Set objContactItem = olkApp.CreateItem
(olContactItem)
Set objContactItem = objFolder.Items.Add
(olContactItem)
End If
With objContactItem
.FullName = Me.Prnom & " " & Me.Nom
.FirstName = Me.Prnom
.LastName = Me.Nom
.BusinessAddress = Me.Ruedomicile
.BusinessAddressCity = Me.Villedomicile
.BusinessAddressPostalCode = Me.Codepostaldomicile
.BusinessTelephoneNumber = Me.Tlphonedomicile
.BusinessFaxNumber = IIf(IsNull
(Me.Tlcopiebureau), "", Me.Tlcopiebureau)
.HomeFaxNumber = IIf(IsNull(Me.Tlcopiedomicile), "",
Me.Tlcopiedomicile)
.Email1Address = IIf(IsNull
(Me.Adressedemessagerie), "", Me.Adressedemessagerie)
'-- This helps to know this Outlook contact came
from Access
.Categories = "EventsContact" & CStr(Me.ID)
.Save
End With
Set objContactItem = Nothing
Set olkNameSpace = Nothing
Set olkApp = Nothing
EH:
If Err = 94 Then
Resume Next
Else
If Err > 0 Then MsgBox Err.Number & " " &
Err.Description
End If
End Sub
This is to send a event booking to the calendar.
There is a problem with the Start property, because the
date and time fields are separate text boxes on this
Access form, and I am not sure how to concantenate the
strings to place in the Start property.
Private Sub cmdOutlookAppointment_Click()
On Error GoTo EH
Dim olkApp As New Outlook.Application
Dim olkCalendar As Outlook.MAPIFolder
Dim olkNameSpace As Outlook.NameSpace
Dim objAppointmentItem As AppointmentItem
Set olkNameSpace = olkApp.GetNamespace("MAPI")
Set olkCalendar = olkNameSpace.GetDefaultFolder
(olFolderCalendar)
Set objAppointmentItem = olkCalendar.Items.Find
("[Categories] = """ & CStr(Me.EventID) & """")
If objAppointmentItem Is Nothing Then
Set objAppointmentItem = olkApp.CreateItem
(olAppointmentItem)
End If
With objAppointmentItem
.Categories = Me.EventID
.Subject = Me.EventType & " " & Me.ClientID.Column
(1)
.Start = CVDate(Me.Event_Date)
If Me.Location.Column(1) = "Residence" Then
.Location = Me.txtRue
Else
.Location = Me.Location.Column(1)
End If
.Save
End With
EH:
If Err > 0 Then
If Err = 94 Then
Resume Next
Else
MsgBox Err.Number & " " & Err.Description
End If
End If
End Sub
Quote:
>-----Original Message-----
>> What do I Dim objContact as? I presume a ContactItem.
>> The help files on Find don't make it clear what to Dim
a
>> variable.
>That's because it depends on the context in which you are
using Find. You can always use Object. If you are
searching a contacts folder for a contact-specific
property, then you could use Outlook.ContactItem.
(Remember that contacts folders may also contain
distribution lists.)
Quote:
>> Is this code on the right track?
>> Set objContact = MyFolder.Items.Find(".........")
>> If Not objContact Is Nothing Then
>> 'Update the properties
>> objContact.BusinessAddress = Me.txtAddress
>> objContact.Save
>> ....
>> else
>> .....
>> End If
>Yes, that's on the right track. See
http://www.slipstick.com/dev/finddate.htm for some general
pointers on building and using Find strings, mixed in with
the specifics about date search strings.
Quote:
>> There are some properties you can't do a Find on, like
>> EmailAddress, is that correct?
>The Help topic on Find covers this.
>> What does SetColumns do and is it useful in this case?
>It caches the Outlook properties that you specify. It can
speed up performance when you need to work with a bunch of
items and only built-in properties. Since you're looking
for just one item, it's not relevant here.
Quote:
message
>> >> This is what I want to do:
>> >> This code is run from an Access form.
>> >> Use the VBA Find method to see if this contact is
>> already
>> >> in the folder. I can use the Email address plus the
>> name
>> >> as the criteria.
>> >> If found, ask the user if the contact is to be
update
>> with
>> >> information from the current Access form.
>> >> I need to know how to update the found record.
>> >> If not found, create a new contact item. I know how
to
>> do
>> >> this.
>.