473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Help! Trying to change code to use Application Object

Hello,

Hope someone can help here, I'm trying to modify the following code to use
an automation object so I don't have deal with CRAPPY REFERENCES! The
reason being is that this will be going on a number of machines that have
different email programs. This is not going to be a runtime deployment,
just a drag and drop mdb front end.

Anyway, here is the code as it sits using the Outlook object libary;

Sub ImportContactsFromOutlook(ySuppressMessages As Boolean)
On Error GoTo ImportContactsFromOutlook_Err
Dim iImportCount As Integer
Dim iUpdatecount As Integer
Dim rst As DAO.Recordset
SetDatabase
Set rst = db.OpenRecordset("FN Contacts")
' Set up Outlook objects.
Dim OL As New Outlook.Application
Dim OLNS As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.ContactItem
Dim objItems As Outlook.Items
Dim prop As Outlook.UserProperty

Set OLNS = OL.GetNamespace("MAPI")
Set cf = OLNS.GetDefaultFolder(olFolderContacts)
Set objItems = cf.Items
iNumContacts = objItems.Count
If iNumContacts <> 0 Then

For i = 1 To iNumContacts

If TypeName(objItems(i)) = "ContactItem" Then
Set c = objItems(i)
rst.Index = "ContactID"
rst.Seek "=", c.EntryID
If rst.NoMatch Then
rst.AddNew
rst!ContactID = c.EntryID
rst!FirstName = c.FirstName
rst!LastName = c.LastName
rst!CompanyName = c.CompanyName
rst!CompanyAddress = c.BusinessAddress
rst!CompanyCity = c.BusinessAddressCity
rst!CompanyRegion = c.BusinessAddressState
rst!CompanyPostal = c.BusinessAddressPostalCode
rst!CompanyTelephone = c.BusinessTelephoneNumber
rst!CompanyFax = c.BusinessFaxNumber
rst!EMail = c.Email1Address
rst!ContactAddress = c.HomeAddress
rst!contactcity = c.HomeAddressCity
rst!ContactRegion = c.HomeAddressState
rst!Contactpostal = c.HomeAddressPostalCode
rst!ContactTelephone = c.HomeTelephoneNumber
rst!ContactFax = c.HomeFaxNumber
rst!JobTitle = c.JobTitle

rst.Update
iImportCount = iImportCount + 1
Else
Dim yUpdated
rst.Edit
If c.EntryID <> rst!ContactID Then rst!ContactID =
c.EntryID: yUpdated = True
If c.FirstName <> rst!FirstName Then rst!FirstName =
c.FirstName: yUpdated = True
If c.LastName <> rst!LastName Then rst!LastName =
c.LastName: yUpdated = True
If c.CompanyName <> rst!CompanyName Then rst!CompanyName =
c.CompanyName: yUpdated = True
If c.BusinessAddress <> rst!CompanyAddress Then
rst!CompanyAddress = c.BusinessAddress: yUpdated = True
If c.BusinessAddressCity <> rst!CompanyCity Then
rst!CompanyCity = c.BusinessAddressCity: yUpdated = True
If c.BusinessAddressState <> rst!CompanyRegion Then
rst!CompanyRegion = c.BusinessAddressState: yUpdated = True
If c.BusinessAddressPostalCode <> rst!CompanyPostal Then
rst!CompanyPostal = c.BusinessAddressPostalCode: yUpdated = True
If c.BusinessTelephoneNumber <> rst!CompanyTelephone Then
rst!CompanyTelephone = c.BusinessTelephoneNumber: yUpdated = True
If c.BusinessFaxNumber <> rst!CompanyFax Then rst!CompanyFax
= c.BusinessFaxNumber: yUpdated = True
If c.Email1Address <> rst!EMail Then rst!EMail =
c.Email1Address: yUpdated = True
If c.HomeAddress <> rst!ContactAddress Then
rst!ContactAddress = c.HomeAddress: yUpdated = True
If c.HomeAddressCity <> rst!contactcity Then rst!contactcity
= c.HomeAddressCity: yUpdated = True
If c.HomeAddressState <> rst!ContactRegion Then
rst!ContactRegion = c.HomeAddressState: yUpdated = True
If c.HomeAddressPostalCode <> rst!Contactpostal Then
rst!Contactpostal = c.HomeAddressPostalCode: yUpdated = True
If c.HomeTelephoneNumber <> rst!ContactTelephone Then
rst!ContactTelephone = c.HomeTelephoneNumber: yUpdated = True
If c.HomeFaxNumber <> rst!ContactFax Then rst!ContactFax =
c.HomeFaxNumber: yUpdated = True
If c.JobTitle <> rst!JobTitle Then rst!JobTitle =
c.JobTitle: yUpdated = True
rst.Update
If yUpdated Then iUpdatecount = iUpdatecount + 1

End If
End If
Next i
rst.Close
If iImportCount > 0 Then
If Not ySuppressMessages Then MsgBox iImportCount & " Contacts
imported successfully.", vbInformation, "Imported Successfully!"
Else
If Not ySuppressMessages Then MsgBox "No new contacts were
found.", vbInformation, "No New Contacts"
End If
Else
If Not ySuppressMessages Then MsgBox "No contacts to import.",
vbInformation, "No Contacts Available"
End If
ImportContactsFromOutlook_Exit:
'strImpMsg = strImpMsg & vbCrLf & iImportCount & " Mail Message" &
IIf(iImportCount > 1, "s", Null) & " imported."
If iImportCount > 0 Or iUpdatecount > 0 Then strImpMsg = strImpMsg &
vbCrLf & iImportCount & " Contact" & IIf(iImportCount > 1 Or iImportCount =
0, "s", Null) & " imported" & vbCrLf & iUpdatecount & " Contact" &
IIf(iUpdatecount > 1 Or iUpdatecount = 0, "s", Null) & " updated"
Exit Sub

ImportContactsFromOutlook_Err:
ErrorBox Err.Number, Err.Description, "Importing Contacts"
Resume ImportContactsFromOutlook_Exit
End Sub

WHen trying to covert it, I get as far as the following;

Set OL = CreateObject("Outlook.Application")
Set OLNS = OL.GetNamespace("MAPI")
Set cf = OLNS.GetDefaultFolder(olFolderContacts)

....and then I get lost, any test code that I've used to step through blows
up no matter what I try to put next.

any ideas?

Thanks!
Jan 12 '06 #1
1 2136
Never mind....got it! ;)
"Rico" <r c o l l e n s @ h e m m i n g w a y . c o mREMOVE THIS PART IN
CAPS> wrote in message news:YDBxf.96600$tl.23247@pd7tw3no...
Hello,

Hope someone can help here, I'm trying to modify the following code to
use an automation object so I don't have deal with CRAPPY REFERENCES! The
reason being is that this will be going on a number of machines that have
different email programs. This is not going to be a runtime deployment,
just a drag and drop mdb front end.

Anyway, here is the code as it sits using the Outlook object libary;

Sub ImportContactsFromOutlook(ySuppressMessages As Boolean)
On Error GoTo ImportContactsFromOutlook_Err
Dim iImportCount As Integer
Dim iUpdatecount As Integer
Dim rst As DAO.Recordset
SetDatabase
Set rst = db.OpenRecordset("FN Contacts")
' Set up Outlook objects.
Dim OL As New Outlook.Application
Dim OLNS As Outlook.NameSpace
Dim cf As Outlook.MAPIFolder
Dim c As Outlook.ContactItem
Dim objItems As Outlook.Items
Dim prop As Outlook.UserProperty

Set OLNS = OL.GetNamespace("MAPI")
Set cf = OLNS.GetDefaultFolder(olFolderContacts)
Set objItems = cf.Items
iNumContacts = objItems.Count
If iNumContacts <> 0 Then

For i = 1 To iNumContacts

If TypeName(objItems(i)) = "ContactItem" Then
Set c = objItems(i)
rst.Index = "ContactID"
rst.Seek "=", c.EntryID
If rst.NoMatch Then
rst.AddNew
rst!ContactID = c.EntryID
rst!FirstName = c.FirstName
rst!LastName = c.LastName
rst!CompanyName = c.CompanyName
rst!CompanyAddress = c.BusinessAddress
rst!CompanyCity = c.BusinessAddressCity
rst!CompanyRegion = c.BusinessAddressState
rst!CompanyPostal = c.BusinessAddressPostalCode
rst!CompanyTelephone = c.BusinessTelephoneNumber
rst!CompanyFax = c.BusinessFaxNumber
rst!EMail = c.Email1Address
rst!ContactAddress = c.HomeAddress
rst!contactcity = c.HomeAddressCity
rst!ContactRegion = c.HomeAddressState
rst!Contactpostal = c.HomeAddressPostalCode
rst!ContactTelephone = c.HomeTelephoneNumber
rst!ContactFax = c.HomeFaxNumber
rst!JobTitle = c.JobTitle

rst.Update
iImportCount = iImportCount + 1
Else
Dim yUpdated
rst.Edit
If c.EntryID <> rst!ContactID Then rst!ContactID =
c.EntryID: yUpdated = True
If c.FirstName <> rst!FirstName Then rst!FirstName =
c.FirstName: yUpdated = True
If c.LastName <> rst!LastName Then rst!LastName =
c.LastName: yUpdated = True
If c.CompanyName <> rst!CompanyName Then rst!CompanyName =
c.CompanyName: yUpdated = True
If c.BusinessAddress <> rst!CompanyAddress Then
rst!CompanyAddress = c.BusinessAddress: yUpdated = True
If c.BusinessAddressCity <> rst!CompanyCity Then
rst!CompanyCity = c.BusinessAddressCity: yUpdated = True
If c.BusinessAddressState <> rst!CompanyRegion Then
rst!CompanyRegion = c.BusinessAddressState: yUpdated = True
If c.BusinessAddressPostalCode <> rst!CompanyPostal Then
rst!CompanyPostal = c.BusinessAddressPostalCode: yUpdated = True
If c.BusinessTelephoneNumber <> rst!CompanyTelephone Then
rst!CompanyTelephone = c.BusinessTelephoneNumber: yUpdated = True
If c.BusinessFaxNumber <> rst!CompanyFax Then
rst!CompanyFax = c.BusinessFaxNumber: yUpdated = True
If c.Email1Address <> rst!EMail Then rst!EMail =
c.Email1Address: yUpdated = True
If c.HomeAddress <> rst!ContactAddress Then
rst!ContactAddress = c.HomeAddress: yUpdated = True
If c.HomeAddressCity <> rst!contactcity Then
rst!contactcity = c.HomeAddressCity: yUpdated = True
If c.HomeAddressState <> rst!ContactRegion Then
rst!ContactRegion = c.HomeAddressState: yUpdated = True
If c.HomeAddressPostalCode <> rst!Contactpostal Then
rst!Contactpostal = c.HomeAddressPostalCode: yUpdated = True
If c.HomeTelephoneNumber <> rst!ContactTelephone Then
rst!ContactTelephone = c.HomeTelephoneNumber: yUpdated = True
If c.HomeFaxNumber <> rst!ContactFax Then rst!ContactFax =
c.HomeFaxNumber: yUpdated = True
If c.JobTitle <> rst!JobTitle Then rst!JobTitle =
c.JobTitle: yUpdated = True
rst.Update
If yUpdated Then iUpdatecount = iUpdatecount + 1

End If
End If
Next i
rst.Close
If iImportCount > 0 Then
If Not ySuppressMessages Then MsgBox iImportCount & " Contacts
imported successfully.", vbInformation, "Imported Successfully!"
Else
If Not ySuppressMessages Then MsgBox "No new contacts were
found.", vbInformation, "No New Contacts"
End If
Else
If Not ySuppressMessages Then MsgBox "No contacts to import.",
vbInformation, "No Contacts Available"
End If
ImportContactsFromOutlook_Exit:
'strImpMsg = strImpMsg & vbCrLf & iImportCount & " Mail Message" &
IIf(iImportCount > 1, "s", Null) & " imported."
If iImportCount > 0 Or iUpdatecount > 0 Then strImpMsg = strImpMsg &
vbCrLf & iImportCount & " Contact" & IIf(iImportCount > 1 Or iImportCount
= 0, "s", Null) & " imported" & vbCrLf & iUpdatecount & " Contact" &
IIf(iUpdatecount > 1 Or iUpdatecount = 0, "s", Null) & " updated"
Exit Sub

ImportContactsFromOutlook_Err:
ErrorBox Err.Number, Err.Description, "Importing Contacts"
Resume ImportContactsFromOutlook_Exit
End Sub

WHen trying to covert it, I get as far as the following;

Set OL = CreateObject("Outlook.Application")
Set OLNS = OL.GetNamespace("MAPI")
Set cf = OLNS.GetDefaultFolder(olFolderContacts)

...and then I get lost, any test code that I've used to step through blows
up no matter what I try to put next.

any ideas?

Thanks!

Jan 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
10
by: Jacek Generowicz | last post by:
Where can I find concise, clear documentation describing what one has to do in order to enable Python's internal help to be able to provide descriptions of Python keywords ? I am in a situation...
0
by: python-help-bounces | last post by:
Your message for python-help@python.org, the Python programming language assistance line, has been received and is being delivered. This automated response is sent to those of you new to...
2
by: BT Openworld | last post by:
I have just had to upgrade to Access 2003 as Access 97 EMail (SendObject) doesn't work when loaded on Windows XP. I'm finding my way around Access 2003 but my biggest problem is getting...
1
by: Tim Marshall | last post by:
I'm putting together my first help file (using Easy Help, http://www.easyhelp.com/). So far, so good. I'm able to use the Help File and Help Context ID to have things from my help file pop up...
3
by: stuart_white_ | last post by:
I've just upgraded from Python 2.3.3 to Python 2.4.2, and, although the new version of Python seems to be running correctly, I can't seem access the help from the interpreter. On Python 2.3.3...
9
by: JJ | last post by:
Do you all use HTML help workshop to create your help system. I am finding it quite clumsy to use. Mayeb because I am not used to using it. Do any of you use any other techniques to create help...
4
by: Fred Flintstone | last post by:
This one baffles me. I'm using VS.Net 2005 and write desktop apps that need built in help. So logically, I figure maybe VS has a help system component built in so I search the help. Hey! ...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.