"Object Variable Not Set"

Hi, i have the follwing codes in the queryopen event , and it will prompt the “Object variable not set” when i create a new document…

Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)

Dim s As New NotesSession

Dim doc As NotesDocument

Dim currentuser As String



Set doc = Source.Document



'doc.InUseBy(0) = ""

If doc.HasItem("InUseBy") Then

	currentuser = doc.InUseBy(0)

	If currentuser ="" Or currentuser = s.username Then

		doc.InUseBy =s.UserName		

		Call doc.Save(False,True)

	End If

End If	

End Sub

This line got some problem(debug) but i dont know why:

If doc.HasItem(“InUseBy”) Then

I am sure that there is a field called InUseBy in the form.

Can someone tell me why? Thanks

Subject: “Object Variable Not Set”

Abu,

When you create a new document, there is no “back-end” document, therefore doc does not yet exist. source.document will only exist once the document has been saved.

If the code needs to stay for existing docs, just put it all within a “If source.isnewdoc=false then” if statement

HTH

Mike

Subject: “Object Variable Not Set”

Hi Abu, you are using a method for the NotesDocumentClass with a NotesUIDocument. You need to reference the uidoc to the doc so you can use this method, i.e. Dim doc As NotesDocument

Set doc = uidoc.Document

if doc.hasItem … etc.

oops - didn’t see you were using queryopen, please disregard this entry.

Subject: RE: “Object Variable Not Set”

No, he’s good on that. The QueryOpen event carries a NotesUIDocument with it. That’s the Source he’s referencing to get his NotesDocument.