Link to home
Start Free TrialLog in
Avatar of backwaterdogs
backwaterdogs

asked on

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")
Avatar of qwaletee
qwaletee

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
SOLUTION
Avatar of HemanthaKumar
HemanthaKumar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of backwaterdogs

ASKER

Gents,

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!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, actually, there is one way using OLE automation of the Notes client instead of COM access to the API.
qwualetee,

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