Initially my issue was I'm getting an over flow because the length of the value in the first two fields (IDs) were longer, and back then I'm using Clng (long). I had to change it to Cstr (string).
I have also updated the first two columns in the view @Text(fieldname), and it's still sorted in ascending order.
I have 4 keys, first two of which are from parent form (but I made it also available in the dialog box form), third and fourth key is coming from the dialog box form.
Code snippet could be found below:
Set lookupdb = session.GetDatabase(lserver$,ldb$)
Set lookupview = lookupdb.GetView(lview$)
Set dateRange = session.CreateDateRange()
Set dateRange.StartDateTime = dateTime1
Set dateRange.EndDateTime = dateTime2
'Variant because of the daterange in keys (4)
Dim keys( 1 To 4 ) As Variant
keys(1) = Cstr(uidoc.FieldGetText("FirstID"))
keys(2) = Cstr(uidoc.FieldGetText("SecondID"))
keys(3) = Trim(uidoc.FieldGetText("Station"))
Set keys(4) = daterange
'Test. This has output. For daterange I used .text so I can see output.
Msgbox keys(1)
Msgbox keys (2)
Msgbox keys (3)
Msgbox daterange.text
Set lookupcoll = lookupview.GetAllDocumentsByKey(keys,True)
If lookupcoll.Count <> 0 Then
Print "Criteria Selection Count : " + Cstr(lookupcoll.count)
Set lookupdoc = lookupcoll.GetFirstDocument
ctr = 0
Do While Not lookupdoc Is Nothing
<code here>
Loop
Print "Ended : " + Now()
Else
Messagebox "No Document Retrieved."
End If
Exit Sub
I am getting the "No Document Retrieved" and when I checked the documentcollection, it has 0 in it.
Please let me know why I'm getting null. Thank you so much.
The GetAllDocumentsByKey method requires that your view, lookupview
, has the first few columns categorized and sorted by the keys you are using to search it.
From the docs:
GetAllDocumentsByKey method
Finds documents based on their column values within a view. You create an array of strings (keys), where each key corresponds to a value in a sorted and categorized column in the view. The method returns the all documents whose column values match each key in the array.
You may need to change your view's design to accommodate the search you are performing.