Using variables in db.search

I am trying to create a db search agent using lotus script and I am trying to pass values from three prompt boxes, one for the name of the field, old value and the new value I want to insert into the field. This is all pretty straight forward. If I do a search just by the form or hard code the name the Field and the old value it also works fine. But I want to be able the select any field and old value. I don’t want to just search by the form name for there are a few thousand documents using that form. Any suggestions?Here is the code

Dim session As New NotesSession

Dim db As NotesDatabase

Dim collection As NotesDocumentCollection

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Dim count As Integer

	

Dim newValue As String

Dim oldValue As String



Field1 = Inputbox("What is the name of the field? ")

oldvalue = Inputbox("What is the old Value? ")



newValue = Inputbox("What is the new Value? ")

	

'searchFormula$ = {Form =  "TA" & Field1= oldvalue}

'This is a try to use the information in the Inputbox but doesn't seem to work!!!!



searchFormula$ = {Form =  "TA" & Field_2 = "oldvalue"}

'This works but I have to hard code the field and its value!!!



count = 0

Set collection = db.Search(searchFormula$,Nothing,0)

Set doc = collection.GetFirstDocument()



While Not(doc Is Nothing)

	count = count +1

	

	If doc.field_2(0) = oldvalue Then

		Call doc.ReplaceItemValue("Field_2", newValue)

	End If

	

	Call doc.Save( True, False )

	Set doc = collection.GetNextDocument(doc)

	

Wend

Messagebox count, MB_OK, "Number of docs changed! "

End Sub

Subject: using variables in db.search

searchFormula$ = {Form = “TA” & Field1=“} & oldvalue & {”}

Once the search has been done, there’s no need to test the value of the field again, so use can use StampAll to set the field value on the entire document collection. It’s hugely faster (as in “not just a little bit faster”) than doing ReplaceItemValue + Save.

Subject: RE: using variables in db.search

searchFormula$ = {Form = “TA” & Field_2 =“} & oldvalue & {”} This code did work for the field name is hard coded “Field_2”

searchFormula$ = {Form = “TA” & Field1 =“} & oldvalue & {”} This didn’t seem to work with Field1 being a variable ?

Subject: RE: using variables in db.search

If the field is a variable, then it has to appear outside the literal string as well:

searchFormula$ = {Form = “TA” & } & Field1 & { =“} & oldvalue & {”}

Subject: RE: using variables in db.search

It worked great Thanks…