GetDocumentByKey returns wrong doc

I am using the GetDocumentByKey method to retrieve a document using a view that has 2 sorted columns. I need to use both columns. Here is my code:

Set docAlevied = view1.getdocumentbykey(mkey,myear)

Since the view is sorted on 2 columns, I have added 2 parameters in the code.

myear is equal to “2006” but the code is returning the “2005” document. The “2006” document does not exist. So why doesn’t it return NOTHING instead of the 2005 document?

Subject: GetDocumentByKey returns wrong doc

Did you try it using the True parameter?

view1.getdocumentbykey(mkey,myear, True)

From designer help:

Set notesDocument = notesView.GetDocumentByKey( keyArray [, exactMatch% ] )

exactMatch%

Boolean. Optional. Specify True if you want to find an exact match. The first document that matches the key exactly is returned. If you specify False (the default) or omit this parameter, a partial match succeeds. A partial match returns the first document that matches the initial characters of the key.

Subject: RE: GetDocumentByKey returns wrong doc

When I trued to add the “True” parameter, I got a compile error.

Subject: RE: GetDocumentByKey returns wrong doc

Your not specifying your key properly (its expecting a key array, not multiple strings), take a look at designer help which will carify but if you want an exact match, you must use True.

Subject: GetDocumentByKey returns wrong doc

Set docAlevied = view1.getdocumentbykey(mkey,myear)

should be like this

dim keys(2) as string

keys(0) = “key0value”

keys(1) = “key1value”

set docAlevied = view1.getDocumentByKey(keys, true) 'or false if you want partial matches

Subject: RE: GetDocumentByKey returns wrong doc

Hello everyone,

i do not know if i am applying in the right place but let’s give it a try :slight_smile:

I have similar situation like this one mentioned here. However I don’t get any document at all.

While running the code it tries to connect to outer lotus notes db and get a document according to a certain tabel number. However the function getdocumentbykey does not return any document at all. The funniest thing is that when I cut and paste the document in an outer database, the function starts working again - pulls out the right document.

Any ideas,???