My app has a button that the user clicks & which then asks for & attaches a file with comments & dates into a table within a rich text field. This provides a nice ui for multiple attachments.Obviously I use Script to do this & in general it works. BUT if the user does two attachments in one session then it does tend to lose the insert position, and then all the text & attachments get stuffed into the last column of the table. & that looks a complete mess. One its gone wrong then it continues to go wrong, even coming completely out of the doc.
My theory is that the RTNavigator sort of loses its way, & once lost gets even more lost. My code (sorry its so long) is below to see if any of you gurus can help.
TIA
’ the field Files is no-editable. This will attach a file to it, associate a comment/title + sign & date it & present in the form of a table
'
Dim session As New NotesSession
Dim uiws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim db As NotesDatabase
Dim doc As notesdocument
Dim rtnav As NotesRichTextNavigator
Dim body As NotesRichTextItem
Dim rtt As NotesRichTextTable
Dim rtrange As NotesRichTextRange
Dim styles(1 To 4) As NotesRichTextParagraphStyle
Dim reason As Variant
'
Set db = session.currentdatabase
Set uidoc= uiws.CurrentDocument
Set doc =uidoc.Document
’
For i% = 1 To 4 Step 1
Set styles(i%) = session.CreateRichTextParagraphStyle
styles(i%).LeftMargin = RULER_ONE_INCH
styles(i%).FirstLineLeftMargin = RULER_One_Inch*0.25
'Sets width of cell
styles(i%).RightMargin = RULER_ONE_INCH*0.75
styles(i%).Alignment = ALIGN_LEFT
Next
styles(1).rightmargin= RULER_ONE_INCH*3.0
styles(2).RightMargin=RULER_ONE_INCH*4.0
Dim style As NotesRichTextStyle
Set style = session.CreateRichTextStyle
style.Bold=True
’ style.FontSize = 8
’ style.NotesFont = STYLE_NO_CHANGE
’ style.NotesColor = Black
Dim item As NotesItem
Set item = doc.GetFirstItem("Files")
If item.type=1280 Then Call doc.removeitem("Files")
Set body = doc.getfirstitem("Files")
If body Is Nothing Then
Set body = doc.CreateRichTextItem("Files")
Call body.AppendText(" ")
End If
Set rtnav = body.CreateNavigator
'While rtnav.GetFirstElement(4) Is Nothing
' Set rtnav = body.CreateNavigator
'Wend
' now apply the style
Call body.appendstyle(style)
If Not(rtnav.FindFirstElement(RTELEM_TYPE_TABLE)) Then
' create a table
rowCount% = 2
columnCount% = 4
Call body.AppendTable(rowCount%,columnCount%,,RULER_ONE_INCH*1.5,styles)
' now set up the first row and position at start of second
Call rtnav.FindfirstElement(RTELEM_TYPE_TABLECELL)
Call body.BeginInsert(rtnav)
Call body.AppendText(" Attachment Name.")
Call body.EndInsert
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Call body.BeginInsert(rtnav)
Call body.AppendText(" Description")
Call body.EndInsert
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Call body.BeginInsert(rtnav)
Call body.AppendText(" Attached By")
Call body.EndInsert
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Call body.BeginInsert(rtnav)
Call body.AppendText(" On")
Call body.EndInsert
style.bold=False
Call body.AppendStyle(style)
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Else
' there was already a table find the end and add a new row to it & set the insert point
Set rtt = rtnav.GetElement
Call rtnav.FindLastElement(RTELEM_TYPE_TABLECELL)
Call rtt.AddRow(1)
style.bold=False
Call body.AppendStyle(style)
Call rtnav.findnextelement(RTELEM_TYPE_TABLECELL)
End If
' there will be a table by now, so append stuff to end of table
Call body.BeginInsert(rtnav)
' ************************************ attach a file
Dim object As NotesEmbeddedObject
attachfile = uiws.OpenFileDialog(False,"Select a file to attach")
If Isempty(attachfile) Then Exit Sub
Set object = body.EmbedObject ( EMBED_ATTACHMENT, "", attachfile(0))
Call body.EndInsert
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Call body.BeginInsert(rtnav)
reason= uiws.Prompt(3,"Attaching Files to Comments Tab","Please supply a description/reason why the file is being attached","")
If Isempty(reason) Then Exit Sub
Call body.AppendText(reason)
Call body.EndInsert
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Call body.BeginInsert(rtnav)
Call body.AppendText(session.CommonUserName)
Call body.EndInsert
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Call body.BeginInsert(rtnav)
Call body.AppendText(Cstr(Today))
Call body.EndInsert
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Call body.Update
doc.saveoptions="1"
'
Call doc.Save(True,False)
Call uidoc.close(True)
Set uidoc = uiws.EditDocument(True,doc)
Call uidoc.GotoField("Fiddle")
doc.saveoptions=""