Object variable not set

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

Else

Messagebox "B"

End If

So, what happened? Thanks.

Subject: object variable not set

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.

Regards,

John

Subject: RE: object variable not set

From what I’ve tested, it is the variable doc that has not been set. Right now, I could not find the reason why it isn’t set.

Sub Click(Source As Button)

Dim s As NotesSession

Dim db As NotesDatabase

Dim uiws As NotesUIWorkspace

Dim uidoc As NotesUIDocument

Dim v As NotesView

Dim doc As NotesDocument

Dim temp As String

Set s = New NotesSession

Set db = s.CurrentDatabase

Set uiws = New NotesUIWorkspace

Set uidoc = uiws.CurrentDocument

Call uidoc.Save

temp = uidoc.FieldGetText(“FirstName”)

Set v = db.GetView(“topic”)

If Not v Is Nothing Then

Set doc = v.GetDocumentByKey(temp)

If doc Is Nothing Then

	Messagebox "Something is Wrong"

Else

	Messagebox "All is Well"

End If

Else

Messagebox "View NOT Set"

End If

End Sub

The message that I got was “Something is Wrong”.

Subject: RE: object variable not set

Subject: object variable not set

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.

Subject: RE: object variable not set

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?

Subject: RE: object variable not set

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).

Subject: RE: object variable not set

Oops, yes I meant TRANSLATION.

Well, I tried to search “Christina”. So i checked did what you suggested, and both values are “Christina”.

Subject: RE: object variable not set

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.

Subject: RE: object variable not set

then i have no idea why mine doesn’t work

Subject: RE: object variable not set

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:

  1. Right after you set the temp variable, enter: msgbox(temp)

  2. 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.

Keep us posted on this. I know I am curious.

Good luck.

Matt

Subject: RE: object variable not set

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. )

Subject: RE: object variable not set

Subject: RE: object variable not set

Well said Willy

Subject: RE: object variable not set

Oops! Sorry, Sorry.

I was reading a wrong version of Designer Help (R5).

Luckily, that’s triggered Christina to double check if the sort radio buttons is correctly set or not.

Sorry for any problem caused.

Subject: RE: object variable not set

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?

Subject: RE: object variable not set

Subject: RE: object variable not set

Because it needs to be either sorted or categorized, but you had “none”.

-rich