[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1119
  • Last Modified:

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")
  • 3
  • 2
2 Solutions
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!
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now