Hi all
I'm trying to set up an Access database that will be able to import
contact information from the lotus notes 6.5 Address book. The idea is
that the code runs from access to import all of the contacts, using
COM.
I've written the following vba code so far to import the contacts
'Set up DAO (Data Access Objects) using an object called RecordSet to
hold table
Dim TempContactRST As DAO.Recordset
'Use existing "Temporary Contact Details" table
Set TempContactRST = CurrentDb.OpenRecordset("Temporary Contact
Details")
'Set up objects required for automation into lotus notes
Dim Session As Object
Dim NotesDB As Object
Dim NotesView As Object
Dim NotesViewNav As Object
Dim NotesEntry As Object
Dim NotesDoc As Object
Dim Handle As Integer
Dim UserName As String
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession")
'Open Address Book database
Set NotesDB = Session.GetDatabase("", "names.nsf")
If NotesDB.IsOpen = True Then
'Do nothing
Else
NotesDB.OPENMAIL
End If
Set NotesView = NotesDB.GetView("Contacts")
Set NotesViewNav = NotesView.CreateViewNav()
Set NotesEntry = NotesViewNav.GetFirstDocument()
While Not (NotesEntry Is Nothing)
Set NotesDoc = NotesEntry.Document
fname = NotesDoc.GetFirstItem("FirstName").Values
lname = NotesDoc.GetFirstItem("LastName").Values
JobTitle = NotesDoc.GetFirstItem("JobTitle").Values
CompanyName = NotesDoc.GetFirstItem("CompanyName").Values
TempContactRST.AddNew
TempContactRST!FirstName = fname(0)
TempContactRST!LastName = lname(0)
TempContactRST!Company = CompanyName(0)
TempContactRST!JobTitle = JobTitle(0)
TempContactRST.Update
Set NotesEntry = NotesViewNav.GetNextDocument(NotesEntry)
Wend
TempContactRST.Close
MsgBox "Finished"
Set Session = Nothing
Set NotesDB = Nothing
The problem i'm having is that because the address book isn't stored as
a relational database format then if one of the fields in the notes
address book has not had data added to it, the field name doesn't exist
in the document. This means that when the vba code tries to access a
field in the notes address book that has no data, the field name doesnt
exist and vba crashes, giving me a run time error 91 - Object variable
or With block variable not set.
Does anyone know a way around this problem? The only solution I can
think of so far is to catch the error then ignore it, but I don't want
to do this incase the error occurs somewhere outside of the address
book access, and is ignored, which could lead to all sorts of problems.
Also if you think my code could be improved in general then any
pointers would be great. I've only just started using vba and only just
started using notes too.
Cheers
Charlie