By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,423 Members | 1,601 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,423 IT Pros & Developers. It's quick & easy.

lotus notes automation to Access using VBA

P: n/a
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

Aug 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

What if you turn error handling on and handle the 91 error in your
code?

Public Sub MySub()
On Error Goto ErrHandler

<code>
Exit Sub

ErrHandler:
if Err.Number = 91 then
'skip the error and go to the next line.
Resume Next
Else
Handle Other Errors...
End if

Aug 1 '06 #2

P: n/a
Thanks for replying

Thats what I mean't in my previous post about catching the error and
ignoring it, and at the moment it looks like it's what I'm going to
have to use. There doesn't seem to be a lot of information around
regarding accessing lotus notes through the COM, which is a bit
annoying.

I think that because the lotus notes database is a document rather than
a relational database, if a field is blank then there is no entry, not
even a null, which means the field simply doesn't exist if there is no
data in it. I know that lotus can be a really a great program, but to a
beginner it's pretty tough getting it to do anything!

Cheers

Charlie

pi********@hotmail.com wrote:
What if you turn error handling on and handle the 91 error in your
code?

Public Sub MySub()
On Error Goto ErrHandler

<code>
Exit Sub

ErrHandler:
if Err.Number = 91 then
'skip the error and go to the next line.
Resume Next
Else
Handle Other Errors...
End if
Aug 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.