Object variable not set

Hi to All

Sir I m having a problem. I have this code in view action formula when i select a document and click on action it changes some field values. it’s working but its showing error object variable is not set.

i m not getting where is the error.

it working fine in other server.

pls help me

Sub Click(Source As Button)

Dim session As New NotesSession

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument

Dim ws As New NotesUIWorkspace 

Dim uidoc As NotesUIDocument 



Set uidoc = ws.CurrentDocument 

Set db = session.CurrentDatabase

Set collection = db.UnprocessedDocuments

Dim counter As Integer 

counter = 0

Set doc = collection.GetFirstDocument()

'''''''''''''''Count number ofDocument in the Collection '''''''''

Dim TotalDocument As Integer

TotalDocument=Collection.Count

If TotalDocument<=0 Then

	Msgbox"Please Select Dcouement !"

	Exit Sub

End If

'''''''''''''''Count number ofDocument in the Collection '''''''''	

While Not(doc Is Nothing)

	doc.Flag="1"

	doc.applicable = "Yes"

	Call doc.Save(True,True)					

	Set doc = collection.GetNextDocument(doc)		

	counter = counter  + 1

Wend	

Msgbox counter & " Document Sucessfully Saved as confirmed Status!"	

uidoc.Close 

End Sub

Subject: Object variable not set

use error handler to rectify the errors by yourself.make the habit to always use error handling mechanism

Subject: Object variable not set

Hi,

You are changing the value in a document from View Action button. That is you are changing the document through backend. You dont need any reference for frontend and that way the code you have used is incorrect. Remove the two lines of code as specified below and that should solve your problem.

Sub Click(Source As Button)

Dim session As New NotesSession

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument

Dim ws As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Set uidoc = ws.CurrentDocument -----> Remove this code

Set db = session.CurrentDatabase

Set collection = db.UnprocessedDocuments

Dim counter As Integer

counter = 0

Set doc = collection.GetFirstDocument()

‘’‘’‘’‘’‘’‘’‘’‘Count number ofDocument in the Collection ‘’’‘’‘’‘’

Dim TotalDocument As Integer

TotalDocument=Collection.Count

If TotalDocument<=0 Then

Msgbox"Please Select Dcouement !"

Exit Sub

End If

‘’‘’‘’‘’‘’‘’‘’‘Count number ofDocument in the Collection ‘’’‘’‘’‘’

While Not(doc Is Nothing)

doc.Flag=“1”

doc.applicable = “Yes”

Call doc.Save(True,True)

Set doc = collection.GetNextDocument(doc)

counter = counter + 1

Wend

Msgbox counter & " Document Sucessfully Saved as confirmed Status!"

uidoc.Close -----> Remove this Code

End Sub

Subject: Object variable not set

Hi,

You are changing the value in a document from View Action button. That means you are changing the document through back end. Why are you trying for a front end reference to the document. Remove the lines of code i specified in the below code and that should solve your problem.

Sub Click(Source As Button)

Dim session As New NotesSession

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument

Dim ws As New NotesUIWorkspace -----> Remove this line

Dim uidoc As NotesUIDocument -----> Remove this line

Set uidoc = ws.CurrentDocument -----> Remove this line

Set db = session.CurrentDatabase

Set collection = db.UnprocessedDocuments

Dim counter As Integer

counter = 0

Set doc = collection.GetFirstDocument()

‘’‘’‘’‘’‘’‘’‘’‘Count number ofDocument in the Collection ‘’’‘’‘’‘’

Dim TotalDocument As Integer

TotalDocument=Collection.Count

If TotalDocument<=0 Then

Msgbox"Please Select Dcouement !"

Exit Sub

End If

‘’‘’‘’‘’‘’‘’‘’‘Count number ofDocument in the Collection ‘’’‘’‘’‘’

While Not(doc Is Nothing)

doc.Flag=“1”

doc.applicable = “Yes”

Call doc.Save(True,True)

Set doc = collection.GetNextDocument(doc)

counter = counter + 1

Wend

Msgbox counter & " Document Sucessfully Saved as confirmed Status!"

uidoc.Close -----> Remove this line

End Sub

Subject: RE: Object variable not set

Thanks Narisma I got it.But here is one quesstion why its not prompting the error message in other server.

It,s prompting the error message in my local server.

Subject: RE: Object variable not set

You mean to say that on other server you are able to make changes to the document with the same View Action button without any error ?

Subject: RE: Object variable not set

yes