Friday, November 28, 2008

Visual FoxPro and MS Outlook Automation to the Rescue

After I first heard about O2 Atom Life supporting Windows Mobile 6.0, I really wanted to upgrade my O2 Atom Life’s operating system to Windows Mobile 6.0 but never found the time. To cut to the chase, I did have some slack time last Wednesday and proceeded with upgrade process.

In order to back-up the contacts on my O2 Atom Life, I used ActiveSync 4.5 to sync my contacts to a new and empty MS Outlook 2003 profile. Before all of you raised your collective eyebrows on my move, let me say the following: I don’t sync the contacts in my O2 Atom Life and my MS Outlook 2003 profile. I only sync the calendar and tasks. After successfully pairing my O2 with the new and empty MS Outlook 2003 profile I proceeded to sync the contacts only. So with all the contacts from my O2 safely transferred to the MS Outlook, I followed the steps in O2’s website in upgrading my operating system to Windows Mobile 6.0. The upgrade process went without a hitch. So now after doing the usual settings on my O2 after the upgrade, I sync’d it with MS Outlook profile which contained my contacts. Again like a charm my contacts are now in my O2 sporting the Windows Mobile 6.0 operating system. Now I wanted to sync my calendar, so I close MS Outlook and opened it again this time using my usual profile and bam it hit me, I need to un-pair my O2 with the new profile and then pair it with the my usual profile. No big deal right, but since I don’t sync my contacts (with my usual profile and O2) only the calendar and tasks, I need to remove the check mark on the sync options for the contacts but by so doing effectively deleting all the contacts in my O2. So now I was in a dilemma. What should one do in such a predicament? Well, when things can’t be done using the software itself, I turn to my expertise in Visual FoxPro (VFP) and automation of MS Outlook. So here are the steps I took:

  1. I opened MS Outlook with the new profile containing the contacts from my O2 Atom Life.

  2. I ran a snippet of VFP code to extract all the contacts and save these as individual VCard files (extension .vcf).

  3. Send the VCard’s from my laptop to my O2 Atom Life via Bluetooth and viola all my contacts were transferred to my O2 Atom Life.


The Visual FoxPro code snippet I used is found below:
 lnContactsFolder = 10
lnVCardType = 6

loOutlook = Createobject("Outlook.Application")
loNamespace = loOutlook.GetNamespace("MAPI")
loContacts = loNamespace.GetDefaultFolder(lnContactsFolder).Items

For Each loContact In loContacts
lcName = loContact.FirstName + loContact.LastName
Wait Window "Saving: " + lcName Nowait
lcPath = Forceext("C:\temp\" + lcName,"vcf")
loContact.SaveAs(lcPath,lnVCardType)
Next

2 comments:

John said...

Hi Erik.

I wondered if you had any experience/knowledge of accessing VFP tables from a Windows Mobile 5 Pocket PC???

I'm trying to do it via a C#.NET Pocket PC application and Visual Studio 2008 is literally blocking any attempts to create a data connection that uses either the VFP OLEDB provider or an ODBC provider that uses VFP! If I'm creating a C#.NET WINDOWS application it allows it, it's only when deving a Pocket PC/WM5 app that it blocks it ...

I think that MS, in their wisdom, have hard-coded out any attempts to access VFP data from Pocket PC/WM5 and only allow SQL connections but I wondered if there was any way around this at all??!!

Salama!

John

Erik Gomez said...

Hi John,

thanks for dropping by my blog. unfortunately no, i don't have any experience in accessing VFP tables from a Windows Mobile Pocket PC.

i will let you know if i do find a way of doing this. by the way, why not post it in www.foxite.com maybe the guys over there have solution for this.

thanks again and good luck.

--
erik

 

Copyright 2007 ID Media Inc, All Right Reserved. Crafted by Nurudin Jauhari