CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2001
    Posts
    13

    HELP! I need to know how to do a search/prevent dupes.

    Hello everyone. I've got limited experience with Visual Basic. I do know some VBScript and such, but I've been put in charge of a database project at work. I'm working on an MS Access 2002 database, and implimented a code to import the records there to import over into the MS Outlook 2002 Contacts folder. However, it copies each and every single record. If I do the import again, it copies all the records over a 2nd time. Can someone help me out with a brief code example that will allow me to search the MS Outlook 'Contacts' folder before data is sent, so that I don't import duplicates into the folder? I'll attach the original source code below:


    Function BatchUpload()

    ' Setup DAO Database Schtuffins.
    Dim oDataBase As DAO.Database
    Dim rst As DAO.Recordset
    Set oDataBase = OpenDatabase _
    ("K:\Bill Garrett\sulphur DB\sulphur.mdb")
    Set rst = oDataBase.OpenRecordset("Contacts")

    ' Setup Outlook Schtuffins.
    Dim ol As New Outlook.Application
    Dim olns As Outlook.NameSpace
    Dim cf As Outlook.MAPIFolder
    Dim c As Outlook.ContactItem
    Dim Prop As Outlook.UserProperty
    Set olns = ol.GetNamespace("MAPI")
    Set cf = olns.GetDefaultFolder(olFolderContacts)

    With rst
    .MoveFirst

    ' Loop through Sulphur's records.
    Do While Not .EOF


    ' Create new Contact item.
    Set c = ol.CreateItem(olContactItem)

    ' Specify form
    c.MessageClass = "IPM.Contact"

    ' Create all prebuilt Outlook fields and make associations
    If ![COMPANY] <> "" Then c.CompanyName = ![COMPANY]
    If ![F_NAME] & ![L_NAME] <> "" Then c.FULLNAME = ![F_NAME] & " " & ![L_NAME]

    ' Create the first property (UserField1) and give value
    Set Prop = c.UserProperties.Add("UserField1", olText)
    If ![CONTACT_ID] <> "" Then Prop = ![CONTACT_ID]

    ' Create the second user property (UserField2) and give value
    Set Prop = c.UserProperties.Add("UserField2", olText)
    If ![REGION] <> "" Then Prop = ![REGION]

    ' Save and close the contact.
    c.Save
    ' c.Close -Can't close or I get an error?

    .MoveNext

    Loop

    End With

    End Function





    Thanks for your time,

    Bill Garrett
    Network Engineer (Not a programmer)
    Capitol Computer Exchange
    www.ccex.com


  2. #2
    Join Date
    Jun 2001
    Location
    Memphis, TN
    Posts
    146

    Re: HELP! I need to know how to do a search/prevent dupes.

    You could use an SQL statement to form your query/filter, something like this...


    In (SELECT [Somedata] FROM [Table1] As Tmp GROUP BY [Somedata] HAVING Count(*)>1

    ...this is a modified SQL statement that I just cut out of an MS Access DB that I made. You might want to take a look at the "Find Duplicates Query Wizard" in Access if you have it. It will create the SQL statement for you. Good luck with your code!


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured