How do you overwrite/update existing documents?

Hi folks,

I have an application which imports data from excel which populates forms within documents. This import will run on a monthly basis so the excel data/values may change. I want to overwrite or update the existing documents. To give you a rough idea of what i’m trying to do here is the code below…

'Set Lotus Notes view and create document …

		Set view = db.GetView("tester")

		Set doc = view.GetDocumentByKey (id)

		

		If  (doc Is Nothing) Then

			Set doc = db.CreateDocument '// Create a new doc 

			doc.Form = "Employee"

			

			doc.id = id		

			doc.Emp_FirstName = firstName

			doc.Emp_LastName = lastName

			doc.Hire_Date = startDate

			doc.Job_Title = jobTitle

			doc.Dep_Name = dept

		Else

			'//this is where i want to overwrite or update the exising document

Subject: how do you overwrite/update existing documents?

Mickey,

If the document already exists, then by definition, doc is not nothing, so just use the same syntax but do not use the db.createdocument method (or set the Form field)

Don;t forget at the end, to do a doc.save(true, true) to save your changes

HTH

Mike

doc.

Subject: RE: how do you overwrite/update existing documents?

Hi Mike,

Thanks for your help so far. I was going through the debugger there now and I’ve noticed that the code doesn’t make to the “else if” part because the “Set doc = view.GetDocumentByKey (id)” part is not setting doc to anything…is this right??? Heres a sample of the code so far…Help please!

'Set Lotus Notes view and create document …

		Set view = db.GetView("tester")

		Set doc = view.GetDocumentByKey (id)

		

		If  (doc Is Nothing) Then

			Set doc = db.CreateDocument '// Create a new doc 

			doc.Form = "Employee"

			

			doc.id = id		

			doc.Emp_FirstName = firstName

			doc.Emp_LastName = lastName

			doc.Hire_Date = startDate

			doc.Job_Title = jobTitle

			doc.Dep_Name = dept

		Elseif ( Not doc Is Nothing) Then

			doc.id = id		

			doc.Emp_FirstName = firstName

			doc.Emp_LastName = lastName

			doc.Hire_Date = startDate

			doc.Job_Title = jobTitle

			doc.Dep_Name = dept



			

		End If

		



		

		Call doc.Save( False, False ) '// Save the new doc

Subject: RE: how do you overwrite/update existing documents?

Mickey,

In the view “tester”, is the first column sorted? Also, is there definately an entry relating to the value of the id variable?

Mike

Subject: RE: how do you overwrite/update existing documents?

Mike

No the column is not sorted, actually just when you mention it the id that is first in the view is not the same as the first one in the excel sheet…would this make a difference??? Yes there is a value for id!

Subject: RE: how do you overwrite/update existing documents?

The column HAS to be sorted.

It doesn;t matter that the first one is not the same as the first one in Excel. Notes searches the column for the match

Once the column is sorted, you should be OK

Mike

Subject: RE: how do you overwrite/update existing documents?

Mike,

Sorted the column but it is still going into the…

		If  doc Is Nothing Then

			Set doc = db.CreateDocument '// Create a new doc 

			doc.Form = "Employee"

			

			doc.id = id		

			doc.Emp_FirstName = firstName

			doc.Emp_LastName = lastName

			doc.Hire_Date = startDate

			doc.Job_Title = jobTitle

			doc.Dep_Name = dept

…part of the code! Any ideas??? Maybe i havent got the column sorted…“Click on column header to sort” is what i have ticked

thanks Mike…

Subject: RE: how do you overwrite/update existing documents?

You need to click either Ascending or Descending on the top of the properties box (way above where it says click on column header to sort)

Subject: RE: how do you overwrite/update existing documents?

Cheers Mike,

You’ve been great (and extremely patient as well!!) Sorry…thanks!

Mickey

Subject: RE: how do you overwrite/update existing documents?

Always a pleasure

Glad to help