Hi
I have searched the forum, and while I can’t believe I’m the first person to come across this problem I can’t find any discussion about it.
Basically I’m using getallentriesby key to return a notesviewentrycollection. I’m not using a notesdocumentcollection because I want the return values sorted in view order.
The code works, but if no entries are found (which is likely and planned behaviour), how do I check for it? The help specifies that the entry collection would be empty and has a count of 0, but I can’t check for either of these because I get an object variable not set error.
What’s the best way round this? I could do a check first using a notesdocumentcollection to see if any docs are returned , but that seems ludicrous to me, there must be some way of testing it.
Thanks for any ideas
Dan
Subject: notesviewentrycollection and isempty
The entry collection should always be set, provided that the view exists. IsEmpty is only a test for Variants. If the collection does not exist, it will be Nothing. If the collection exists but is empty, then GetFirstEntry will return Nothing.
Subject: RE: notesviewentrycollection and isempty
Stan
Thanks, my brain must have melted this afternoon - a simple ‘Is nothing’ worked fine.
I did find that getfirstentry or checking the count didn’t work though, as it throws up an object variable not set error. This is different than a notesdocumentcollection, and why I was getting very confused.
Dan
Subject: RE: notesviewentrycollection and isempty
Are you sure you’ve got that right? I just tried it and it looks to me like GetAllEntriesByKey does, in fact, return an empty collection if there are no matching documents. You might have a different issue. I’m using a later version, but as a policy, we really try to not make changes to the product that would break existing apps, so it’s unlikely this has changed.
Here’s my test code, which if you’re using the Notes client to read this, you can try out with the button below.
Dim session As New NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim entrycoll As notesviewentrycollection
Set db = session.CurrentDatabase
Set view = db.getview("2. Author\Flat")
Set entrycoll = view.GetAllEntriesByKey("Zelda Cassalory")
If entrycoll Is Nothing Then
Msgbox "GetAllEntriesByKey returned Nothing"
Else
Msgbox entrycoll.Count & " matches found"
End If
Subject: RE: notesviewentrycollection and isempty
Andre
OK, yesterday was obviously a bad day, although I do have an issue with this still.
What was happening was that my key in the getallentriesbykey is in fact a company name, looking duplicates in our contacts’ database.
The problem occurs when there is no company name (when the contact’s home address is being looked up), this returns nothing, not an empty collection.
When there is a key and it’s not found it returns an empty collection.
As your code implies, I think I have to check for both eventualities.
Cheers
Dan
Subject: RE: notesviewentrycollection and isempty
So you’re calling GetAllEntriesByKey with a key of “” (empty string) and it returns Nothing. I confirm that behavior.
I suppose you could do the search regardless and check the return value twice. However, it would be more efficient to test the key value first and not bother to do the search if you have nothing to search for.
Subject: RE: notesviewentrycollection and isempty
You’re right of course - I’ll do that
Cheers
Dan
Subject: notesviewentrycollection and isempty
Dan,
My guess is that it is the view object that is not set and giving you the error. Use the debugger to step through it and verify that the view object is actually getting set correctly.
Ron