LotusNotes 8.5 - Adding a row to a table with a bu

2019-09-07 22:49发布

问题:

I am an intern and learning LotusNotes currently, so am not very fluent with it yet.

My question is, how can I program an action button to add a row to an existing table in LotusNotes 8.5?

I have tried the following code, but it has not worked for me,


Sub Click(Source As Button)
Dim uiw As New NotesUIWorkspace
Dim uidoc As NotesUIDocument 
Set uidoc = uiw.CurrentDocument
Dim doc As NotesDocument
Set doc = uidoc.Document    

Dim Body As NotesRichTextItem
Set body = doc.GetFirstItem("Body")
If body Is Nothing Then
Msgbox "Click on the Reset the demo action to create the table first."
End If

Dim rows As Integer, rownumber As Integer, numrowstoadd As Integer
Dim strrownumber As String, strrowstoadd As String

Dim rtnav As NotesRichTextNavigator 
Set rtnav = body.CreateNavigator 
Dim rttable As NotesRichTextTable
Set rttable = rtnav.GetFirstElement(RTELEM_TYPE_TABLE)
If rttable Is Nothing Then
Msgbox "No table created - use the Reset the demo action first."
Else
rows=rttable.RowCount
strrowstoadd = Inputbox("Enter the number of rows to add.")
If Isnumeric( strrowstoadd ) Then
numrowstoAdd = Cint(strrowstoAdd)
If numrowstoAdd <= 0 Then
Msgbox "Enter a number greater than zero."
Exit Sub
End If
Else
Msgbox ("Enter a integer number only.")
Exit Sub
End If

strrownumber = Inputbox("Enter the number corresponding to the row to start adding at, no greater than " & rows & ".")
If Isnumeric( strrownumber ) Then
rownumber = Cint(strrownumber)
If rownumber < 0 Or rownumber > rows Then
Msgbox ("You entered too high a number or a number less than zero, try again.")
Exit Sub
End If
Else
Msgbox ("Enter a integer number only.")
Exit Sub
End If

Call rttable.AddRow(numrowstoadd, rownumber)    
End If  

doc.save True, True
uidoc.Close
Call uiw.EditDocument(False,doc)
End Sub

Any help would be great. Thanks!

回答1:

Without taking a detailed look at your code, I believe the fundamental problem you are facing is most likely the fact that the NotesRichText class is part of what we call the "back end classes" for Notes. That means that it is one of the objects that represents the in-memory version of data from an NSF file in its storage format, and this is not the same as the "front end classes". Those are objects that represent the data that the user sees and edits. You can tell the front end from back end classes by the prefix NotesUI for all the front end classes.

The thing is, the objects in the front end classes and back end are kept synchronized except for rich text, and what that means is that changes that you make to NotesRichText objects do occur in memory, and the are saved to the NSF file if you call NotesDocument.save(), but they are not reflected in what you see on the screen until you do something to reload the front end data from the back end. Here's a link to a wiki page that demonstrates a technique for doing that.



回答2:

You wrote "but it has not worked for me". I tried your code and it works. I suggest you just few changes in order to make it work better: close the doc before working with the table in the RT (back end) just before Dim Body As NotesRichTextItem

uidoc.save 'to save any change done
doc.saveoptions = "0"'to avoid do you want to save
uidoc.Close True

in place of the 3 last lines:

doc.Save True, True
Call uiw.EditDocument(True,doc)

NB you have to add Exit Sub after "Click on the Reset the demo action to create the table first" and after "No table created"