Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Portland, Maine, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Find Method in Outlook

    I am developing an application to import records from a FoxPro database into a custom contact form in Outlook. I am using Outlook 2000 SR1. I have the code working to import the records into the contact folder. However, this procedure is going to be run regularly to update Outlook from FoxPro so I want to see if the record already exists. So conceptually I will go to the first record in FoxPro, then check for its existence in Outlook. If it is not in Outlook, I will add it. If the record is there, it will be updated. Both FoxPro and Outlook have a field "custno". It is the key field in FoxPro.

    I was working with the find function, but can't get this to work. Following is enough code so you can see what I am doing. Any thoughts/suggestions?

    Do While Not rsSBT.EOF

    strFilter = rsFP!custno
    Set itm = objFolder.Items.Find("[CustomerID] = strfilter")

    Set itm = objFolder.Items.Add("IPM.Contact.clients")

    With itm
    If IsNull(rsFP!custno) = False Then itm.CustomerID = rsFP!custno
    If IsNull(rsFP!company) = False Then itm.CompanyName = rsFP!company
    If IsNull(rsFP!company) = False Then itm.FileAs = rsFP!company

    If IsNull(rsFP!contact) = False Then itm.UserProperties("TechContact") = rsFP!contact

    ' Save the record
    .Save
    End With
    ' Move to next record and loop
    rsSBT.MoveNext
    Loop

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Find Method in Outlook

    Hi Darryl,
    I think you need to change:
    Set itm = objFolder.Items.Find("[CustomerID] = strfilter")
    to something like:
    Set itm = objFolder.Items.Find("[CustomerID] = " & strfilter)
    because at the moment I think it's searching for an item where the CustomerID equals the text 'strFilter' rather than whatever value is stored in strFilter.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Portland, Maine, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find Method in Outlook

    My question/problem has more to do with checking the results of the find operation. After the Set itm ... statement, I want to do an if...then...else statement. When I do "If itm = true" I get an error "Object Variable or With block variable not set". I just can't seem to get the syntax correct.

    Any suggestions?

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Find Method in Outlook

    what IS itm? Objects can't be true or false, only their values and properties can be.
    Charlotte

  5. #5
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    Portland, Maine, USA
    Posts
    296
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find Method in Outlook

    My only problem was the wrong syntax on the find statement. This is what worked.

    Set itm = objFolder.Items.Find("[CustomerID] = '" & strFilter & "'")

    If itm Is Nothing Then
    Set itm = objFolder.Items.Add("IPM.Contact.clients")
    End If

    Thanks for the input and suggestions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •