By Chris Doig
Here's a scenario. You have written a marvelous subform called RevHistory that creates a full audit trail of all document changes, as seen in Figure A. Applications are endless, and the paranoid want you to use it everywhere.
FIGURE A
You're now the proud owner of this handy RevHistory subform. (click for larger image)
To make RevHistory a general-purpose subform for your library, you create the RevHistory Setup subform. This subform goes on a tab on the database profile form and configures RevHistory for that database.
But there's a problem! For RevHistory to get the setup parameters from the RevHistory Setup subform, you must know the name of the database profile form. However, you can't hard-code the database profile form name because that would mean your subform would no longer be a general-purpose object.
How can you get information from the setup subform when you don't know the name of the database profile form?
The solution
The trick is to use an intermediate profile document. The RevHistory subform gets the name of the database profile form from this intermediate document and then opens the database profile. Here's how you do it.
On your RevHistory Setup subform you include the code to create the intermediate profile document automatically. The first time you save the database profile document that contains the RevHistory Setup subform, your code creates the intermediate profile document with a known form name. (Although it has a form name, this intermediate document does not actually require a form.)
When you save a document with the RevHistory subform, it uses this known profile document to look up the name of the database profile document. Voila! You have a handle on the database profile document with the setup information.
Creating the intermediate profile document
The script below goes in the PostSave event of the database setup profile document. This script creates an intermediate profile document every time you save the database profile document. If you rename your database setup profile document, you must open it and save it in order to update the intermediate profile document with the name of the new database setup profile document.
'The RevHistory Setup subform can go on a db setup form of any name.
'However, the RevHistory script must know what form this is.
'This script creates a "link" profile document. The RevHistory script
knows the name of the "link"
'document, and uses it to find the db setup document that contains the
RevHistory setup subform.
'This code automatically creates a "link" profile document, if one does
not exist.
Dim session As New NotesSession
Dim db As NotesDatabase
Dim Profiledoc As NotesDocument
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set doc = source.Document
Set Profiledoc = db.GetProfileDocument("RevHistory Profile")
Profiledoc.RevHistoryForm = doc.form(0)
Call Profiledoc.Save(False, False)
End Sub