Das Ganze lässt sich auch realisieren, ohne das Dokument speichern zu müssen.
Grundidee:
1. backendoc wird erstellt
2. das zughörige uidoc wird geöffnet
3. der Wert des Feldes, welches die berechnete Teilmaske definiert wird vom User (bspw. via Dialog) geändert
4. das uidoc wird wieder geschlossen (passiert aber erst, wenn der Code fertig ausgeführt wurde)
5. ein neues uidoc wird basierend auf dem backendoc (noch im memory) geöffnet
6. die referenz von backendoc zum alten uidoc wird gelöscht
7. dem backendoc wird das document property des neuen uidoc zugewiesen...
Tönt relativ abgefahren, funktioniert aber ganz gut.
Hier der ScriptCode...
Sub insertSubform(strSubformposition As String)
'modify a rich text field or the selection for a computed subform WITHOUT having to save and re-open the document
'The basic idea:
'1. creation of a backend-document
'2. open the correspondig uidoc
'3. close uidoc (will not happen until the code is finished executing
'4. open a new uidoc based on the backend-document that is still in memory
'5. delete the reference of the backend-document to the old uidoc
'6. assign the document property of the new uidoc to the backen-document
'-> with this procedure it is possible to load subforms without having to save > close > reopen the document
'arguments: strSubformposition: Top | Bottom
Const FORM = "Vorlage"
Dim session As NotesSession
Dim ws As NotesUIWorkspace
Dim db As NotesDatabase
Dim uidocOld As NotesUIDocument 'the original instance of the uidoc
Dim uidocNew As NotesUIDocument 'the new instance of the uidoc
Dim docThis As NotesDocument
Dim strSubform As String
Set session = New NotesSession
Set ws = New NotesUIWorkspace
Set db = session.CurrentDatabase
Set uidocOld = ws.CurrentDocument
Set docThis = uidocOld.document
docThis.Form = FORM
'find all available subforms in this db
Const TITLE = "title"
Const PROMPT = "prompt"
Dim strSubFormsArray() As String
Dim varSubForms As Variant
Dim intJ As Integer
varSubForms = dbDesign.subformDocuments
Redim strSubFormsArray(Ubound(varSubForms)) As String
Forall varK In varSubForms
strSubFormsArray(intJ) = varSubForms(intJ).~$TITLE(0)
intJ = intJ + 1
End Forall
strSubform = ws.Prompt( PROMPT_OKCANCELCOMBO, TITLE, PROMPT, strSubFormsArray(0), strSubFormsArray )
If strSubformPosition = "Top" Then
'make sure the subform can not be used twice
If docThis.SubformBottom(0) <> strSubform Then
docThis.SubormTop = strSubform
Else
Exit Sub
End If
docThis.SubformTop = strSubform
Elseif strSubformPosition = "Bottom" Then
'make sure the subform can not be used twice
If docThis.SubformTop(0) <> strSubform Then
docThis.SubformBottom = strSubform
Else
Exit Sub
End If
End If
'prevent user form beeing asked to save document
docThis.SaveOptions = "0"
'close uidoc. it won't actually happen until the code is finished executing
Call uidocOld.Close(True)
'create a new uidoc and open the backend doc that is still in memory
Set uidocNew = ws.EditDocument(True, docThis)
'delete the reference to uidocOld
'this is necessary because the code below affects it if left in memory
Set docThis = uidocNew.Document
'remove the saveoptions field
docThis.RemoveItem("SaveOptions")
End Sub
Gruss
Ray