Results 1 to 6 of 6

Thread: Create Contact in Folder/Delete Contact in Folder

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Posts
    419

    Create Contact in Folder/Delete Contact in Folder

    Hey, awhile ago I posted here asking for help with outlook 2003 and my problems were resolved...however when I try working with outlook 2000...my code breaks. I have the following code for just adding a contact to outlook:

    Code:
    Dim ol As Outlook.Application
    Dim ns As Outlook.NameSpace
    Dim fl As Outlook.Folders
    Dim itmContact As Outlook.ContactItem
    
        ' grab Outlook
        Set ol = New Outlook.Application
        
        ' get MAPI reference
        Set ns = ol.GetNamespace("MAPI")
        ' Create new Contact item
        Set itmContact = ol.CreateItem(olContactItem)
        
         ' Setup Contact information...
       With itmContact
          .FullName = "James Smith"
          .Anniversary = "09/15/1997"
          
          ' saving b-day info creates info in the calendar
          .Birthday = "9/15/1975"
          
          .CompanyName = "Microsoft"
          .HomeTelephoneNumber = "704-555-8888"
          .Email1Address = "[email protected]"
          .JobTitle = "Developer"
          .HomeAddress = "111 Main St." & vbCr & "Charlotte, NC 28226"
           
        End With
        
       ' Save Contact...
       itmContact.Save
       
       Set ol = Nothing
       Set ns = Nothing
       Set itmContact = Nothing
       
       MsgBox "Done."
    That works, but what I would like to do is...upon clicking the button that executes that code, I would like it to find the Contact folder named '123'...clear the contacts from it....then add the contact above. When I try working with addresslists (like I did in 2k3), I get errors saying Type Mismatch.
    Code:
    If LostAngel.Tag = "Programming" then
       LostAngel.Caption = "Awake"
    Else
       LostAngel.Caption = "Dreaming of Code"
    End If

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Create Contact in Folder/Delete Contact in Folder

    Well you are not loggin on to the outlook profile/session that may be one part. You are using Early Binding that is specific to 2003 reference. For this you should be using Late Binding with no reference to Outlook.

    See my faq item on Early and Late binding
    http://vbforums.com/showthread.php?t=406640
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Posts
    419

    Re: Create Contact in Folder/Delete Contact in Folder

    I just looked, and that post speaks of sending a mail message...but not saving a contact...im sorry if I sound really stupid with this. The above code works fine...do you perhaps know the syntax to add it to a specific contact folder (instead of the root contact folder)?
    Code:
    If LostAngel.Tag = "Programming" then
       LostAngel.Caption = "Awake"
    Else
       LostAngel.Caption = "Dreaming of Code"
    End If

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Create Contact in Folder/Delete Contact in Folder

    Well I guess you didnt read it then as that was not about sending email but the process of Early binding vs Late binding and how it can help you to support multiple versions of Outlook. What is generating the type mismatch error?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Lively Member
    Join Date
    Nov 2006
    Location
    Austria
    Posts
    109

    Re: Create Contact in Folder/Delete Contact in Folder

    I have the same problem:
    i know, how to find, add, delete, update a contact-item, BUT:

    i want to do all the operations NOT in the default contact folder, but in
    my own contact folder named "sigiK" - so i first have to find this folder out from outlook - how can i do this ??

  6. #6
    Lively Member
    Join Date
    Nov 2006
    Location
    Austria
    Posts
    109

    Re: Create Contact in Folder/Delete Contact in Folder

    solved ...

    finding myFolder:

    Code:
            
    Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")
    Dim oContacts As Outlook.MAPIFolder 
    oContacts = FindMyFolder(oNS.Folders)
    
        Private Function FindMyFolder(ByVal F As Outlook.Folders) As Outlook.MAPIFolder
    
            Dim wf As Outlook.MAPIFolder
            Dim cf As Outlook.MAPIFolder
    
            For Each wf In F
                If wf.Name = "MyFolder" Then Return wf
                If wf.Folders.Count > 0 Then
                    cf = FindMyFolder(wf.Folders)
                    If Not cf Is Nothing Then Return cf
                End If
            Next
    
            Return Nothing
    
        End Function
    adding contact:
    Code:
    oContact = oContacts.Items.Add
    With oContact
           .LastName = ....
           [.......]
           .User1 = 5
           .Save()
    End With
    finding contact:

    Code:
    oContact = oContacts.Items.Find("[User1] = '5'")
    sorry, if code seems stupid, but i am a greenhorn ...

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