Getdocumentbykey problem

I’m running into probems using getdocumentbykey.

The key equals to the third categorized sorted column in the view I’m looking to. I know how to get this in formula language but not in LS.

I’m getting the error: Variant does not contain an object.

Here is the code I’m using:

Dim key As String

If DocOne.type(0) = “sample” Then

key = DocOne.samplea(0)

Else

key = DocOne.sampleb(0)

End If

'…ok have the key ready

Set ViewTwo=db.Getview(“myview”)

Dim Col2 As NotesDocumentCollection

Set Col2 = view.GetDocumentByKey (key, True )

Set DocTwo = Col2.GetFirstDocument

While Not (DocTwo Is Nothing)

Thanks for any help!!!

Subject: getdocumentbykey problem

The getDocumentByKey method only returns the first document of the view matching your key.

If you want to use a collection, use getAllDocumentsByKey. note that the results you’ll get won’t be view sorted. Read the help for further information on this.

Subject: RE: getdocumentbykey problem

Would this be a better way?

NotesView.getAllEntriesByKey?

This returns a NotesViewEntryCollection, which contains NotesViewEntry objects that are in view sort order.

Subject: RE: getdocumentbykey problem

Choosing between getDocumentByKey, getAllDocumentsByKey and GetAllEntriesByKey depend on what you need.

All of these solutions will give you the possibility to find the documents you’re looking for.

With getDocumentByKey, you get the first document corresponding to the key. From this point, you might then navigate to the next one (following order view) until some criteria is met.

With getAllDocumentsByKey you get an unsorted document collection with only the documents responding to the key.

with getEntriesByKey you get a view sorted collection of document entries. This solution requires you to write a bit more code… but this method is quite efficient, because view entries are cached in memory.

What do you really need? If you need to get the documents regardless of the order, go for getAllDocumentsByKey. If order matter, then choose between getDocumentByKey (combined with a getNextDocument) and getAllEntriesByKey.

I hope this helps.

Subject: RE: getdocumentbykey problem

Based on the key, I need the get the docs how they appear in the view. The key is a person’s name so the collection need to be in alphabetical order.

Subject: getdocumentbykey problem

This goes in there too of course.

Dim DocTwo As NotesDocument

Dim ViewTwo As NotesView

Subject: getdocumentbykey problem

Regarding your key, this may help (I think)…

Dim key() As String

  • and then -

key(0) = DocOne.sampleb(0)