Solved

Convert contactitems from access to outlook

Posted on 2003-11-26
7
547 Views
Last Modified: 2012-06-27
I've run into a problem
This export the items from access to outlook. My problem is I do not wat to export the items to the default folder of outlook but to a custom folder the I have made myself.
The foldername is Quick and it is in the root of my outlook today, type is contact items
How do I do this.
Thanx to ansvers

Private Sub Convert_outlook_Click()

' Maak DAO Objects.
   Dim oDataBase As DAO.Database
   Dim rst As DAO.Recordset
   Set oDataBase = CurrentDb
   Set rst = oDataBase.OpenRecordset("vrijwilligers")

' Maak Outlook Objects.
   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
   Dim lngPosition As Long
   Dim varReturn As Variant
   
   lngCount = rst.RecordCount
   strMessage = lngCount & " contact Adressen overzetten naar Outlook -- doen?"
   lngResult = MsgBox(strMessage, vbYesNo, "beginnen?")
      'Exit if user says No
   If lngResult = vbNo Then Exit Sub
   strMessage2 = lngCount & " Adressen te gaan"
   varReturn = Application.SysCmd(acSysCmdInitMeter, strMessage2, lngCount)
   Set olns = ol.GetNamespace("MAPI")
   Set cf = olns.GetDefaultFolder(olFolderContacts)
   'GetDefaultFolder(olFolderContacts)
   i = 1
   With rst
      .MoveFirst

' doorloop de accessdatabase.
      Do While Not .EOF
      For lngPosition = 1 To lngCount

' Maak een nieuw contactitem.
         Set c = ol.CreateItem(olContactItem)

         ' Specify which Outlook form to use.
         ' Change "IPM.Contact" to "IPM.Contact.<formname>" if you've
         ' created a custom Contact form in Outlook.
         c.MessageClass = "IPM.Contact"

         ' Create all built-in Outlook fields.
         If ![sx] <> "" Then c.Title = ![sx]
         If ![Voornaam] <> "" Then c.FirstName = ![Voornaam]
         If ![Achternaam] <> "" Then c.LastName = ![Achternaam]
         If ![straat] <> "" Then c.HomeAddressStreet = ![straat]
         If ![gemeente] <> "" Then c.HomeAddressCity = ![gemeente]
         If ![Pcode] <> "" Then c.HomeAddressPostalCode = ![Pcode]
         If ![Land] <> "" Then c.HomeAddressCountry = ![Land]
         If ![Telefoon] <> "" Then c.HomeTelephoneNumber = ![pf] & "/" & ![Telefoon]
         If ![fax] <> "" Then c.HomeFaxNumber = ![pf] & "/" & ![fax]
         If ![gsm] <> "" Then c.MobileTelephoneNumber = ![gsm]
         If ![E-mailadres] <> "" Then c.Email1Address = ![E-mailadres]
         '
         ' Save the contact.
         c.Save
      strMessage2 = lngCount - lngPosition & " Adressen te gaan"
      varReturn = Application.SysCmd(acSysCmdInitMeter, strMessage2, lngCount)
      varReturn = Application.SysCmd(acSysCmdUpdateMeter, lngPosition)
      .MoveNext
      Next lngPosition
      Loop
   End With
varReturn = Application.SysCmd(acSysCmdClearStatus)
   DoCmd.Hourglass False
End Sub
0
Comment
Question by:GoossensF
  • 2
  • 2
7 Comments
 
LVL 9

Expert Comment

by:svenkarlsen
ID: 9823737
Hi GoossensF,

You just avoid using .DefaultFolder().

NameSpace is a collection of all folders and property .Folders holds all. When you .use .DefaultFolder it's like asking VB to do a search within the namespace for the default folder for e.g. Contacts or Calendar.

You can check what the NameSpace 'is looking at' by:

myNameSpace.PickFolder method, - this will bring up a selection box for folder (sometimes a neat function ;-)

Use this to assign your custom folder:
   Set myFolder = myNameSpace.folders("Folder Name")

"Folder Name" can be a little tricky, if display name has been changed, it's still the original folder name that counts.


Kind regards,
Sven
0
 

Author Comment

by:GoossensF
ID: 9824158
So far I am with you but how do I adjust my code for this, I think I am in a deadlock :)
I have tried some things but it wont work
0
 
LVL 9

Accepted Solution

by:
svenkarlsen earned 50 total points
ID: 9824391
GoossensF,

Drop (or comment out) this line:
    > Set cf = olns.GetDefaultFolder(olFolderContacts)

Add this line instead/below:

    Set cf = olns.folders("Quick")

If you don't get the required result, try commenting out that line and put in this:

    set cf = olns.PickFolder

This should bring up an explorer window where you can see the available folders, - if Quick is not there, maybe it has another name in the namespace? Try guessing ?


Sven
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 9832223
Interesting app for transferring back and for th from Outlook and Access:

http://www.downlinx.com/proghtml/199/19941.htm
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 9883138
If you have not yet put this one to rest you could also check out using Outloo Redemption to write straight to your Contacts folder via code from Access.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question