< Back

Document Subject: Grab All Fields in Database and sort
Hint Short Cut: Add this to your code & documentation to help you find this page.
http://#DatabaseFields or http://A555F9/nn.nsf/ByAlias/DatabaseFields

This script grabs all the fields in a database by going through the forms, uniques them and then sorts them.




 

'this code grabs all the fields in the database and sticks them in the flds field
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
fieldCount = 0
Redim Preserve f(0) As String
Forall form In db.Forms
 
 If Isempty(form.Fields) Then
   'Messagebox form.Name & " has no fields"
 Else

  Forall field In form.Fields
   f(fieldcount)= field
   fieldcount=fieldcount+1
   Redim Preserve f(fieldcount)
  End Forall

 End If  

End Forall
'Messagebox "postopen " & Ubound(f)
Dim uiw As New notesuiworkspace
Dim uidoc As notesuidocument
Set uidoc = uiw.CurrentDocument

Dim doc As notesdocument
Set doc = uidoc.document

Dim fun As Variant
fun =Arrayunique(f)

'Messagebox "postopen " & Ubound(fun)



Dim temp As String
'sort the fun array
For a=1 To Ubound(fun)-1
 For b=Ubound(fun) To a Step -1
  If fun(b) < fun(b-1) Then
   temp=fun(b-1)
   fun(b-1)=fun(b)
   fun(b)=temp
  End If
 Next b
Next a

 'poulate the field in the open form if required
'Call doc.ReplaceItemValue("flds",fun)