Results 1 to 13 of 13

Thread: Saving data into Microsoft Outlook

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    118

    Saving data into Microsoft Outlook

    Hello,

    I have 20,000 Names and phone numbers stored in the access table. Is there a way to use VB code to go to Microsoft Outlook under Contacts and create a Subfolder, and then go to the access table pulling the data (Names and phone numbers) and then save it into that Subfolder?


    Thanks.

  2. #2
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    Here is how to create a sub-contact folder under the default contact folder and how to create a new ContactItem within that folder. All you have to do is add your database code and loop through the records and add a new item for each one. Let me know if you need anything else.

    Code:
    Public Sub CreateSubContactFolder()
    Dim app As Outlook.Application, MFld As MAPIFolder, nItm As ContactItem
    
    Set app = CreateObject("Outlook.Application")
    Set MFld = app.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts).Folders.Add("Imported Contacts", olFolderContacts)
    Set nItm = MFld.Items.Add(olContactItem)
    
    nItm.FullName = "John A. Doe"
    nItm.FileAs = "Doe, John A."
    nItm.BusinessFaxNumber = "555-555-5555"
    nItm.Email1Address = "[email protected]"
    nItm.Save
    nItm.Close olSave
    
    Set nItm = Nothing
    Set MFld = Nothing
    Set app = Nothing
    End Sub
    BTW - I'm using Outlook 2000, but I believe this works the same in Outlook 97.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    118
    thank you very much RealisticGraphics, I'll give a try.

    H.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    118
    Hi RealisticGraphics,

    The code that you provided works very good, but there's little tiny problem with that. Every time it goes throught line "nItm.BusinessFaxNumber", a small window(Location Information) pops up. Is there a way to avoid having that window to pop up?

    Thanks

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    118
    And also when it saves a new contact info, it saves on top of the previous contact info. It doesn’t move next.

  6. #6
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    That sounds like you're not resetting the object each time through the loop. Besure that the "MFld.Items.Add(olContactItem)" statement is inside the loop and that the "Set nItm = Nothing" statement is just right after you close the contact.

    Also, are you running on an exchange server? I can not duplicate the problem with the box coming up on Business Fax. I'm just running a pop account off it here but I know that I've seen the box before at work (if it is the same thing). Could you maybe post a screen capture of the box that is coming up? Thanks.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    118
    I've attached the screenshot see if you can figure it out.

    Thanks

  8. #8
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    I don't see an attachment, try it again.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  9. #9

    Thread Starter
    Lively Member
    Join Date
    May 2002
    Posts
    118
    How do I attach a file. I used the Attach file but it doesn't seem to work. Any idea?

  10. #10
    New Member
    Join Date
    Aug 2001
    Location
    South Africa :)
    Posts
    15

    add to existing contacts folder

    Hi there, this works like a dream when creating a new Contacts Folder, but what if I want to add contacts to an existing Contacts Folder?? I have played around with the set Mfld part, but am not sure what option to use there..

  11. #11
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    Just set a mapi folder object to the name of the folder you want to grab... For instance, lets say you want to add contacts to the Imported Contacts folder we just created. You'd just use the following code.

    Code:
    Dim app As Outlook.Application, MFld As MAPIFolder, EFld As MAPIFolder, nItm As ContactItem
    
    Set app = CreateObject("Outlook.Application")
    Set MFld = app.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
    Set EFld = MFld.Folders.Item("Imported Contacts")
    Set nItm = EFld.Items.Add(olContactItem)
    
    nItm.FullName = "John A. Doe2"
    nItm.FileAs = "Doe2, John A."
    nItm.BusinessFaxNumber = "666-666-6666"
    nItm.Email1Address = "[email protected]"
    nItm.Save
    nItm.Close olSave
    
    Set nItm = Nothing
    Set EFld = Nothing
    Set MFld = Nothing
    Set app = Nothing
    Notice that you still have to set an object to the root folder. Let me know if you need anything else.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  12. #12
    New Member
    Join Date
    Aug 2001
    Location
    South Africa :)
    Posts
    15
    I understand, so if I only want to import contacts in my root contacts folder, I can omit this part "Set EFld = MFld.Folders.Item("Imported Contacts")" and refer only yo Mfld, right?

  13. #13
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655

    Wink

    You've got it.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

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