NotesRichTextItem(doc, "string") not working, pls help

having all sorts of grief trying to get up to speed with the notes objects in VBA.  In searching through all the examples and docs that I have the following should pose no problems, but the last line generates the following error: "compile error sub or function not defined" All the docs reference two arguments for this 'constructor' what am I missing?  have tried late binding as well. thanks!

Dim session As New Domino.NotesSession
Dim db As New Domino.NotesDatabase
Dim doc As New Domino.NotesDocument
Dim dc As New Domino.NotesDocumentCollection

    Call session.Initialize
    Set db = session.GetDatabase("", "copy of testcoach.nsf")
    Set dc = db.AllDocuments
    Set doc = dc.GetNthDocument(421)
    Set rtitem = NotesRichTextItem(doc, "ImageFilePath")
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You are confusing sytaxes, I think, as well as versions of the object model.  To use a constructor in VB, you need the NEW keyword.  But Notes's COM interface only supports constructing the NotesSession object.  ll other objects don't use a constructor -- they are obtained as member properties of "parent" objects (model hierarchy), or via methods of those parent objects.  The limitation on "NEW" is documented in the explanation of COM in Domino Designer help under the "general exceptions" heading (i.e., COM works just like LotusScript except for these exceptions).

Since you don't use NEW< VBA is assuming that you must have a built-in, add-on, or you own defined function named NotesRichTextItem


The help for NotesRichTextItem describes creating it via NEW or via NotesDocument.CreteRichTextItem.  NEW is out for you, so just use:

set rtitem = doc.createRichTextItem(doc,"ImageFilePath")


Is 421 significant to you, or a random pick?  Just to let yu know, if you loop over a collection, it is MUCH more efficient to use getFirstDocument/getNextDocument than to use getNthDocument
FYI : You have to use the notes objects as OLE Objects (COM)


Dim session as Object
Dim db as Object
Dim doc As Object
Dim dc As Object
Dim rtitem as Object
Set session = CreateObject("Lotus.NotesSession")
Call session.Initialize("password")

    Set db = session.GetDatabase("", "copy of testcoach.nsf")
    Set dc = db.AllDocuments
    Set doc = dc.GetNthDocument(421)
'    Set rtitem = NotesRichTextItem(doc, "ImageFilePath")
Set rtitem = doc.GetFirstItem( "ImageFilePath")

backwaterdogsAuthor Commented:

Thanks for the input!  qwalatee, I tried as you suggested, but get an error on the document as the document already has the item "ImageFilePath".  This is a field that stores a binary image file (embedded_attachment) and I am trying to figure out how to replace the image file.

I believe I need to somehow associate the RichTextITem to a field in the document, which the only way I see is using the NotesRichTextItem() (method/constructor or whatever this is).  My next step is to then embed the attachment as described on several other entries.

Can you please help with this?  What is the best/quickest method from VBA to update/replace an embedded attachment?

Thanks very much for your help and patience!
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

You can only replace the image file if you replace the whole field.  There might be a way in R6 with NotesRichTextNavigator, but I've completely given up on ever getting anything useful to work using RTnavigator.

If you do want to replace the whole field (image content AND ANYTHING ELSE), then do as follows:

Const rtf = "ImageFilePath"
If doc.hasItem(rtf) Then
    Set rtitem = doc.GetFirstItem( rtf )
End If
Set rtitem = doc.createRichTextItem( rtf )

Now you can do with RTF as you like.  Next problem is, how do you get the image in there?  If it is a file, and you just want to attach it, then no problem.  But I don't know f a way using the COM classes to "paste" a bitmap image in there.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Well, actually, there is one way using OLE automation of the Notes client instead of COM access to the API.
backwaterdogsAuthor Commented:

thanks very much for this reply, been away for the last day or so, but i will try your suggestion asap.  I believe I can use rtitm.EmbedObject(EMBED_ATTACHMENT.....) can't I?

Should have posted this earlier, but this is the lotus scipt that is currently running and that I am trying to port to VB:

Sub Initialize
      Dim session As New NotesSession
      Dim workspace As New notesuiworkspace
      Dim uidoc As notesuidocument
      Dim db As NotesDatabase
      Dim doc As Notesdocument
      Dim dc As Notesdocumentcollection
      Dim object As NotesEmbeddedObject
      Dim s As String
      Dim i As Integer
      Set db = session.CurrentDatabase
      Set dc = db.UnProcessedDocuments   ' Selected slides
      If dc.count > 0 Then
            For j =  1 To dc.Count
                  Set doc = dc.GetNthDocument(j)
'      Set uidoc = workspace.currentdocument
'      Set doc = uidoc.document      
            '      filename = doc.filename(0)
      '            pre=Left(filename, 9)
      '      post=
                  newfiles = "c:\vc files\" & "Slide" & doc.SlideNumber(0) & ".PNG"
                  Set rtitem = New NotesRichTextItem( doc,"ImageFilePath" )
                  Set object = rtitem.EmbedObject _
                  ( EMBED_ATTACHMENT, "", newfiles)
                  Call doc.Save( True, True )
                  Print " We are on # " & j & " ....  Speed demon"
            Next j
            Print "Successfully added  files. "
      End If
End Sub

Any more help on porting this is greatly appreciated.  John
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.