Find method in Outlook 
Author Message
 Find method in Outlook

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.


Sat, 30 Apr 2005 12:18:14 GMT  
 Find method in Outlook
Setting properties in an Outlook item is simple. Once you have the item (objContact):

    objContact.prop = "whatever" ' for builtin properties
    objContact.UserProperties("prop") = "whatever" for custom properties

then

    objContact.Save

See http://www.slipstick.com/dev/propsyntax.htm for more information on Outlook property syntax.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
     Microsoft Outlook Programming: Jumpstart
     for Administrators, Power Users, and Developers
     http://www.slipstick.com/books/jumpstart.htm

Quote:

> 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.



Sun, 01 May 2005 04:24:46 GMT  
 Find method in Outlook
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.

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

There are some properties you can't do a Find on, like
EmailAddress, is that correct?
What does SetColumns do and is it useful in this case?

Quote:
>-----Original Message-----
>Setting properties in an Outlook item is simple. Once you

have the item (objContact):
Quote:

>    objContact.prop = "whatever" ' for builtin properties
>    objContact.UserProperties("prop") = "whatever" for
custom properties

>then

>    objContact.Save

>See http://www.slipstick.com/dev/propsyntax.htm for more

information on Outlook property syntax.
Quote:
>--
>Sue Mosher, Outlook MVP
>Outlook and Exchange solutions at http://www.slipstick.com
>Author of
>     Microsoft Outlook Programming: Jumpstart
>     for Administrators, Power Users, and Developers
>     http://www.slipstick.com/books/jumpstart.htm




Quote:
>> 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.

>.



Mon, 02 May 2005 00:16:19 GMT  
 Find method in Outlook

Quote:
> 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.

Quote:
> 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:



> >> 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.



Mon, 02 May 2005 03:03:45 GMT  
 Find method in Outlook
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.

>.



Mon, 02 May 2005 11:34:34 GMT  
 Find method in Outlook
Depending on exactly how you have the Access form set up, you might just concatenate the strings, then use CDate:

objAppointmentItem.Start = CDate(Me.DateBox & " " & Me.TimeBox)

Quote:

> 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.



Mon, 02 May 2005 12:00:18 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Find method of Outlook.MAPIFolder fails intermittently

2. I'm trying to use the Find method in Outlook to locate a Contact by the field [Customer ID] = "1234".

3. I'm trying to use the Find method in Outlook to locate a Contact by the field [Customer ID] = "1234".

4. Field Names for Outlook Items Find Method

5. Field Names for Outlook Items Find Method

6. ADO find method compare with DAO findfirst method...

7. Finding "FIND" method

8. Finding a record without Find/Seek methods...

9. Finding a record without Find/Seek methods...

10. vba items.find how to find a quoted word within a subject in outlook

11. Properties and Methods For olMailItem In Outlook

12. Properties and Methods For Outlook MailItem

 

 
Powered by phpBB® Forum Software