' Use Search Engine to find documents
' create a list of the scopes that are available to use
Dim listBrokers As Long
lStatus = LL_ValueAlloc(listBrokers)
lStatus = LL_ValueSetAssoc(listBrokers)
lStatus = LL_ValueSetList(listBrokers)
gTryStatus = Try(LL_GetSearchBrokers(lSession, listBrokers), "Error 1002xx LL_GetSearchBrokers(lSession, listBrokers)"
' what is the number of brokers found in the list
Dim intNumberofBrokers As Long
gTryStatus = Try(LL_ValueGetLength(listBrokers, intNumberofBrokers), "Error 1002xx LL_ValueGetLength(listBrokers, intNumberofBrokers)"
Dim lAssoc As Long
Dim intNodeID As Long
lStatus = LL_ValueAlloc(lAssoc)
Dim intLoop As Integer
intLoop = 0
buf = ""
Do Until Left(buf, siz) = "Enterprise" ' look for the enterprise scope
' get the association from the list of brokers
gTryStatus = Try(LL_ListGetValue(listBrokers, intLoop, lAssoc), "Eroor 1002xx LL_ListGetValue(listBrokers, intLoop, lAssoc)"

lStatus = LL_AssocGetInteger(lAssoc, "NodeID", intNodeID)
lStatus = LL_AssocGetString(lAssoc, "NodeName", buf, 255, siz)
intLoop = intLoop + 1
Loop
Dim vSelectlist As Long
' //Define value objects
lStatus = LL_ValueAlloc(vSelectlist)
lStatus = LL_ValueSetList(vSelectlist)
' //Set up the list of fields for ApplyQuery to return
lStatus = LL_ValueSetLength(vSelectlist, 4)
' //Note: OTObject must be in this list for ApplyQuery to work
lStatus = LL_ListSetString(vSelectlist, 0, "OTDataID"

'//The objects ID
lStatus = LL_ListSetString(vSelectlist, 1, "OTName"

' //Object Name
lStatus = LL_ListSetString(vSelectlist, 2, "OTObject"

lStatus = LL_ListSetString(vSelectlist, 3, "OTOwnerID"

'//The objects VolumeID
' OraRecordsetAmanda.Fields("PermitNumber"

.value
Dim strWhere As String ' same entry enteres in the search criteria
'Should look like "(Attr_166758_2 : *) and-not (Attr_166758_3 : *) and-not (Attr_166758_2 : 0000)"
strWhere = "(Attr_" & intBuildingAmandaRelated & "_2 : *) " & _
"and-not (Attr_" & intBuildingAmandaRelated & "_3 : *) " & _
"and-not (Attr_" & intBuildingAmandaRelated & "_2 : 0000)"
Dim lngQueryResults As Long
lStatus = LL_ValueAlloc(lngQueryResults)
lngRecordsCounter = 0
lngChangesCounter = 0
lngErrorsCounter = 0
intSearchStart = 0
Do
DoEvents
' search Livelink
lStatus = LL_ApplyQuery(lSession, intNodeID, vSelectlist, strWhere, 0, "", intSearchStart, 1000, "LivelinkQueryLanguage", lngQueryResults)
intSearchStart = intSearchStart + 1000
Dim intNumberofReturns As Long ' the number of documents returned
lStatus = LL_ValueGetLength(lngQueryResults, intNumberofReturns)
Dim lngDocumentLoop As Long ' used for the for next loop for every document in the search return
For lngDocumentLoop = 0 To intNumberofReturns - 1