Get all field names of a Notes form
Get all field names of a Notes form.
I often needed some functionality for configuration documents (i.e. for exporting/importing data) to give the user a choice of all available fields in a special form.
Given server a path of a database, the following two routines find:
1. all available forms in a database 2. all fields in a form in a database 3. the delivered bubblesort just sorts the elements in the list in alphabetical order
Combined was uiworkspace.prompt or for example a postopen event. The result of these routines can be used to fill a list of choices in a form.
Function funcGetForms( strServer As String, strPath As String) As Variant '************************************************************************** '* Given server (strServer) and path (strPath) of a database '* this routine returns a list of all forms available in this database '* The if-clause marked with ### is used to exclude the hidden '* and system forms from the choice list. '************************************************************************** Dim db As NotesDatabase Dim form As NotesForm Dim retval As Variant Set db = New NotesDatabase( strServer, strPath ) If Not db.Isopen Then Msgbox "The database " & strPath & " isn't available on server " & strServer Exit Function End If Redim retval(0) Forall frm In db.Forms If Left( frm.name, 1 ) <> "$" And Left(frm.name, 1) <> "(" Then '### If Isarray(frm.aliases) Then If frm.aliases(0) = "" Then retval( Ubound(retval) ) = frm.name 'no alias = take the name of the form Else retval( Ubound(retval) ) = frm.aliases(Ubound(frm.aliases)) 'The last alias in the list is normally the one who is written into the form field of corresponding documents End If Else retval( Ubound(retval) ) = frm.name End If Redim Preserve retval( Ubound(retval) + 1) End If End Forall Redim Preserve retval( Ubound(retval) - 1) retval = funcBubbleSortList( retval, "") funcGetForms = retval End Function Function funcGetFields( strServer As String, strPath As String, strForm) As Variant '************************************************************************** '* Given server (strServer) and path (strPath) of a database and '* the name or alias (strForm) of a form in this database '* this routine returns a list of all fields available in this form '* The if-clause marked with ### is used to exclude the hidden '* and system forms from the choice list. '************************************************************************** Dim db As NotesDatabase Dim form As NotesForm Dim retval As Variant Set db = New NotesDatabase( strServer, strPath ) If Not db.Isopen Then Msgbox "The database " & strPath & " isn't available on server " & strServer Exit Function End If If strForm = "" Then Msgbox "Please give a name or alias for the form" Exit Function End If Set form = db.GetForm( strForm ) If form Is Nothing Then Msgbox "This form doesn't exist in the database" Exit Function End If Redim retval(0) Forall fie In form.Fields retval( Ubound(retval) ) = fie Redim Preserve retval( Ubound(retval) + 1) End Forall Redim Preserve retval( Ubound(retval) - 1) retval = funcBubbleSortList( retval, "") funcGetFields = retval End Function Function funcBubblesortList( varList As Variant, varList2 As Variant ) As Variant '********************************************************************** '* Sorts an inputlist (varList) alphabetically and returns sorted '* list as a result '* varList2 can be empty (""). If varList2 contains a list with an '* equal number of elements, then these elements are sorted after '* sort order of varList1. I.E. two lists with customer names and ids to '* be sorted "corresponding" per name: '* varList1 = B:D:A:C varList2 = 1:2:3:4 '* result A:B:C:D varList2 = 3:1:4:2 '*-------------------------------------------------------------------------------------- '* varList2 is changed in itself (by reference) '********************************************************************** Dim retval As Variant Dim varTmp As Variant Dim lngCountA As Long Dim lngCountB As Long Dim lngMax As Long 'Ubound Dim lngMin As Long 'Lbound lngMax = Ubound( varList ) lngMin = Lbound (varList) 'Eigentlich immer 0 retval = varList For lngCountA = lngMin To lngMax For lngCountB = lngMin To (lngMax - 1) If retval(lngCountB) > retval(lngCountB + 1) Then varTmp = retval( lngCountB) retval( lngCountB ) = retval( lngCountB + 1) retval( lngCountB + 1 ) = varTmp 'second list is sorted after sort-order of first list If Isarray(varList2) Then If varList2(0) <> "" Then varTmp = varList2( lngCountB) varList2( lngCountB ) = varList2( lngCountB + 1) varList2( lngCountB + 1 ) = varTmp End If End If End If Next Next funcBubblesortList = retval End Function