Update Field


%REM
    Agent Update Field
    Description: Interactively updates field value of selected documents
    	Accepts string numeric, date and multiple values; or a formula.
    	Optionally computes with form.
    Created Jun 9, 1999 by Fernando Levi
%END REM
Option Public
Option declare
Sub Initialize
	Dim w As NotesUIWorkspace
	Dim s As NotesSession 
	Dim db As NotesDatabase
	Dim view As NotesView
	Dim FromDoc As NotesDocument
	Dim ToDoc As NotesDocument
	Dim NextDoc As NotesDocument
	Dim c As NotesDocumentCollection
	Dim doc As NotesDocument
	Dim Item As NotesItem
	Dim result As variant
	Set s = New NotesSession
	Set db = s.CurrentDatabase
	Set c = db.UnprocessedDocuments
	Dim FieldName, FieldValue, FormName As String
	Dim multiple, numeric, dateField, formul, ComputeWithForm As integer
	FieldName = Inputbox$ ( "Input field name to update", "Field Name" )
	If FieldName = "" Then Exit Sub
	FieldValue = Inputbox$ ( "Input new value for " & FieldName & " (leave blank to delete)", "Field value" )
	numeric = False
	dateField = False
	On Error Resume Next
	If Val ( FieldValue ) <> 0 And InStr( FieldValue, "/") > 0 Then
		Select Case MessageBox("Is it a date?", 4, "date field?")
		Case 6
			dateField = True
		Case 7
			dateField = False
		Case Else
			Exit Sub
	End Select
	End If
	If Instr( FieldValue, ":") > 0 Then
		Select Case Messagebox("Is it a multiple value field?", 4, "multiple?")
		Case 6
			multiple = True
		Case 7
			multiple = False
		Case Else
			Exit Sub
		End Select
	End If
	If dateField = 0 And (Val ( FieldValue ) <> 0 Or FieldValue = "0") Then
		Select Case Messagebox("Is it a number field?", 4, "number?")
		Case 6
			numeric = True
		Case 7
			numeric = False
		Case Else
			Exit Sub
		End Select
	End If
	On Error Goto 0
	If dateField = False And numeric = False And Instr(FieldValue,"@") > 0 Then
		Select Case Messagebox("Is it a formula?", 4, "Formula?")
		Case 6
			formul = True
		Case 7
			formul = False
		Case Else
			Exit Sub
		End Select
	End If
	Select Case MessageBox("Compute document with Form?", 4, "Compute With Form?")
	Case 6
		ComputeWithForm = True
	Case 7
		ComputeWithForm = False
	Case Else
		Exit Sub
	End Select
	Dim i, iTot As Long
	Dim t0, t As NotesDateTime
	iTot = c.Count
	Set t0 = New NotesDateTime(Now)
	Do
		Set t = New NotesDateTime(Now)
		Print Int(t.TimeDifferenceDouble(t0))
	Loop Until t.TimeDifferenceDouble(t0) / 60 > 0
	For i = 1 To c.Count
		Set t = New NotesDateTime(Now)
		Print CStr(i) + " / " + CStr(iTot) + " estimated " + CStr(Int(t.TimeDifferenceDouble(t0) / 60 / i * (iTot - i))) + " minutes"
		Set doc = c.GetNthDocument(i)
		If Ucase(doc.Form(0)) = Ucase(FormName) Or FormName = "" Then
			If FieldValue = "" Then
				Do
					Set item = doc.GetFirstItem( FieldName )
					If Not ( item Is Nothing ) Then Call item.Remove
				Loop Until item Is Nothing
			Else
				If dateField Then
					Dim DateTime As New NotesDateTime (FieldValue)
					Set item = doc.ReplaceItemValue ( FieldName, DateTime)
				Elseif numeric Then
					Set item = doc.ReplaceItemValue ( FieldName, Val(FieldValue) )
				Elseif formul Then
					result = Evaluate (FieldValue, doc)
					Set item = doc.ReplaceItemValue ( FieldName, result )
				elseIf multiple Then
					Set item = doc.ReplaceItemValue ( FieldName, Split(FieldValue,":") )
				else
					Set item = doc.ReplaceItemValue ( FieldName, FieldValue )
				End If
			End If
			If ComputeWithForm Then
				Call doc.ComputeWithForm(False,False)
			End If
			print doc.Save ( True, True )
		End If
	Next i
End Sub
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...