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! 1 2106
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! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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! ...
|
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...
|
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...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |