I have got a field to capture a value.When I click a button, I need to be able to search in the view to find that value in a specific field in all the documents in a view.
I have written a code below and its not picking up the value.
ub Click(Source As Button)
Dim session As New NotesSession
Dim wks As New NotesUIWorkspace
Dim item As NotesItem
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Set db = session.CurrentDatabase
Set collection = db.UnprocessedDocuments
Set doc = collection.GetFirstDocument()
While Not(doc Is Nothing)
Set item = doc.getFirstItem( "fldStockNumber" )
If item.Contains(doc.GetItemValue("fldSStockNumber")) Then
doc.TrueFalse="True"
Call doc.Save( False, True )
Else
doc.TrueFalse="False"
Msgbox "Item not in Stock"
Call doc.Save( False, True )
End If
Set doc = collection.GetNextDocument(doc)
Wend
Call wks.ViewRefresh
End Sub
Please help me troubleshoot my code
Subject: Searching for a Value in documents in a view.
easiest way - create a view that is categorized on the field, then use GetAllDocumentsByKey.
dim view as NotesView
dim coll as NotesDocumentCollection
set view = db.Getview(“ViewName”)
set coll = view.GetAllDocumentsByKey(doc.FieldValue(0), true)
'true means exact matches only
if not coll is nothing then
'do your stuff here
end if
Subject: RE: Searching for a Value in documents in a view.
I have tried the code below with “Inventory” as the view Name and “fldSStockNumber” being the field that captures a value somebody is trying to search for in the view.
I have a folder named Search to which I need to put all the documents that match the field value.
But I am gettin an error msg to say
“Variant does not contain an object”.Pliz help me out.
Sub Click(Source As Button)
Dim view As NotesView
Dim coll As NotesDocumentCollection
Set view = db.Getview("Inventory")
Set coll = view.GetAllDocumentsByKey(doc.fldSStockNumber(0), True)
'true means exact matches only
If Not coll Is Nothing Then
coll.PutAllInFolder("Search")
End If
End Sub
Subject: RE: Searching for a Value in documents in a view.
The code I gave you was to insert into what you already had not stand-alone code. You haven’t declared or set “doc” that’s why you’re getting the error.