Monday, September 26, 2011

Performing a Search

(Globals) Declarations
Dim uidoc As NotesUiDocument
Dim doc As NotesDocument
Dim collection As NotesDocumentCollection

PostOpen Event
Sub Postopen(Source As Notesuidocument)
     Set uidoc= source
     Set doc = source.document    
End Sub

Click Event
Sub Click(Source As Button)
     Dim RetCode As Integer
    
     '-- A vendor must be entered
     If doc.Vendor(0) = "" Then
          RetCode% = Messagebox("Please Select a Vendor", MB_OK + MB_ICONSTOP, "Invalid Vendor")
          uidoc.gotofield("Vendor")
          Exit Sub
     End If
    
     '-- Instantiate a BIKEPARTS.NSF NotesDatabase object
     Dim db As New Notesdatabase( "", "PGN2\BIKEPART.NSF")
    
     '-- Instantiate a NotesDatetime object
     Dim datetime As New NotesDateTime( "1/1/90")
    
     '-- Create search string for database search
     searchformula$ = "Vendor = " & """" + doc.Vendor(0) + """"
    
     '-- Perform Search
     Set collection = db.search( searchformula$, datetime, 0 )
    
     '-- Dont automatically reload front end fields
     uidoc.AutoReload = False
    
     '-- Populate the table via the backend
     Call PopulateTable
    
     '-- Reload the backend values to the front end
     Call uidoc.reload
    
End Sub

(Globals) PopulateTable
Sub populateTable
    
     '-- Declare  NotesItem Reference Variables for strings
     Dim p As NotesItem
     Dim t As NotesItem
     Dim d As NotesItem
    
     '-- Initialise String Fields
     doc.PartNo = ""
     doc.Type = ""
     doc.Dimension = ""
    
     '-- Set NotesItem Reference Variables for Strings
     Set p = doc.getfirstitem("PartNo")
     Set t = doc.getfirstitem("Type")
     Set d = doc.getfirstitem("Dimension")
    
     '-- Declare Dynamic array for Cost
     Dim costArray() As Single
    
     '-- Get First Document in Collection
     Dim qdoc As NotesDocument
     Set qdoc = collection.getfirstdocument
    
     '-- Initialise Dynamic Array Index
     index = 0
    
     '-- Populate table with Collection
     Do While Not ( qdoc Is Nothing )
         
          '-- Append Strings via NotesItem method
          p.appendtotextlist( qdoc.partno(0) )
          t.appendtotextlist( qdoc.type(0) )
          d.appendtotextlist( qdoc.dimension(0) )
         
          '-- Build Single array
          Redim Preserve costArray(index )
          costArray(index) = qdoc.cost(0)
          index = index + 1
         
          '-- Get Next Document in Collection
          Set qdoc = collection.getnextdocument( qdoc)
     Loop
    
     '-- Assign cost array to backned document item
     doc.cost = costArray
    
End Sub

No comments:

Post a Comment