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

Posted on 2004-11-29
Last Modified: 2013-12-18
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")
Question by:backwaterdogs
    LVL 31

    Expert Comment

    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
    LVL 24

    Assisted Solution

    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")


    Author Comment


    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!
    LVL 31

    Accepted Solution

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

    Expert Comment

    Well, actually, there is one way using OLE automation of the Notes client instead of COM access to the API.

    Author Comment


    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
    Problem "Can you help me recover my changes?  I double-clicked the attachment, made changes, and then hit Save before closing it.  But when I try to re-open it, my changes are missing!"    Solution This solution opens the Outlook Secure Temp Fold…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now