I’m getting an error “Object Variable Not Set” when I’m assigning a NotesDocument variable to a view and performing a .GetDocumentByKey(). I’ve successfully retrieve the view but I’m not sure why I’m getting this error message.
Below is section of codes where I got the error.
Dim temp As String
temp = uidoc.FieldGetText(“FirstName”)
Dim v As NotesView
Dim doc As NotesDocument
Set v = db.GetView(“topic”)
If Not v Is Nothing Then
Set doc = v.GetDocumentByKey(temp, True)
If doc Is Nothing Then
Messagebox "A"
End If
You should be able to step through your code with the LS debugger to identify which object is not being set. Step into each line an examine the object to see what’s failing.
There isn’t enough code here for anyone to guess what’s not being set. For example, the db object does not show where it’s set, or to what value. Also, you didn’t mention the context of how this code is executed; ie, action button, hotspot, doc event.
Have you verified that in the view “topic” the column of first names is sorted, and also that the FirstName you’re searching for exists. Since you’ve specified ‘True’ in the parameter, values must match exactly. If you find the name in the view, check to see if there are trailing spaces.
Yes, I’ve sorted the first column which is also the FirstName. I’ve checked on “Click on column header to sort ascendingly” in the column properties.
Even if I didn’t specify “True”, is still gave me the same message “Something is Wrong”. How do I check if the word has trailing spaces? I’ve used @Trim(FirstName) in the InputValidation for that particular field though, is that what you mean?
The code is unable to find the doc using the criteria specified in the variable temp. I would open the document properties in the document where the button resides, and check the value in the field “FirstName”. Then go to the “topic” view, select the document that should have been returned, and check the document properties again for the field FirstName. What are the values you see?
The @trim(FirstName) should have been in the “Input TRANSLATION” (Probably what you meant).
I copied your code AS IS into a button on a form (A). Added a field called FirstName with keywords “John”, “Jane”, “Mark”. Created another form (B) with the field FirstName. Created 1 doc for John, 1 for Jane. Created a view (topic) that showed the documents created with form B. Had FirstName in the first column, sorted in ascending order. Composed Form A, selected John, clicked on the button, and got the msg “All is Well”. Same when I pick Jane. I get “Something is Wrong” when I pick Mark. I’ve not changed a single line of your code, and it works. Check the data and the view.
You said earlier that you sorted the first column of the view. You went on to say you checked the “click header to sort column”. I dont understand how you have it set. Is it both?
Put a couple of lines temporarily in you code:
Right after you set the temp variable, enter: msgbox(temp)
Next line: msgbox(cstr(len(temp)))
Now when you run it, see if the prompts help you understand.
You should also manually navigate to the topic view and look at it to see if you can identify any issues there.
One tiny thing that may miss out is that for the methodview.getDocumentByKey to work, you must CATEGORIZE the first column to have a single-value field. This is documented in the designer help.
(However for the GetALLdocumentsByKey method to work using a key, you only need to have at least one column sorted. )
I’ve found out my problem. Apparently, I didn’t click on the sort radio buttons but on the check box. After that, select one of the sort radion buttons other that “None” and that solved it.
So, Willy, if there isn’t a need to categorize the first column, how come I couldn’t get my codes running?