db.Search Formula help

I must be having a bad day because I cannot get this db.Search formula to work correctly:

searchFormula = {Form = “" + formName + "” & " + fields + " = “" + locationOriginal + "”}

Totally lost - just want it to look like:

Form = “FormName” & FieldName = “FieldValue”

Here is the agent’s full code:

Sub Initialize

On Error Goto ProcessError



Dim s As New NotesSession   

Dim db As NotesDatabase

Dim dbApp As New NotesDatabase("", "")

Dim dc As NotesDocumentCollection

Dim dcApp As NotesDocumentCollection

Dim doc As NotesDocument

Dim docControl As NotesDocument

Dim profiledoc As NotesDocument	

Dim profiledocCodes As NotesDocument	

Dim view As NotesView

Dim viewControl As NotesView

Dim dateTime As New NotesDateTime(Cstr(Datenumber(2000, 5, 1)))

Dim currentUser As String

Dim message As String

Dim locationOriginal As String

Dim locationNew As String

Dim dbName As String

Dim formName As String	

Dim serverName As String

Dim searchFormula As String

Dim dbList As Variant

Dim fieldName As Variant

Dim notesOrWeb As Variant

Dim Continue As Variant

Dim x As Integer



Set db = s.CurrentDatabase

Set view = db.GetView("Keywords")

Set viewControl = db.GetView("ControlAgentsLocationByFilePath")

notesOrWeb = DetermineClientType

currentUser = GetCurrentUser(notesOrWeb)	

Set profiledoc = db.GetProfileDocument("CodesInfo", currentUser)

Set profiledocCodes = db.GetProfileDocument("OtherCodesInfo", currentUser)



'Get the values...

serverName = profiledoc.ServerName(0)

locationOriginal = profiledocCodes.location_Original(0)

locationNew = profiledocCodes.location_New(0)



'Let's get the list of dbs, forms, and field names...

Set doc = view.GetDocumentByKey("Master List: HR Databases for Control Agents", True)

dbList = doc.SubKeywords



Forall dbs In dbList

	'Let's get all the Control Agent documents...

	Set dc = viewControl.GetAllDocumentsByKey(dbs, True)

	If dc.Count > 0 Then

		x = 0

		For x = 1 To dc.Count

			If x = 1 Then

				Set docControl = dc.GetFirstDocument

			Else

				Set docControl = dc.GetNextDocument(docControl)

			End If

			formName = docControl.ca_FormAlias(0)

			fieldName = docControl.ca_FieldNames				

			'Let's open the database...

			Call dbApp.Open(ServerName, dbs)

			Forall fields In fieldName

				'Get all the documents based on the formName and Original Location...

				'searchFormula = {Form = """ + formName + """ & @Contains(" + fields +"; """ + locationOriginal + """)}

				searchFormula = {Form = "\" + formName + \"" & " + fields + " = "\" + locationOriginal + \""}

				Set dcApp = db.Search(searchFormula, dateTime, 0)

				If dcApp.Count > 0 Then

					'Mark all the documents to the new Location...

					Call dcApp.StampAll(fields, locationNew)						

				End If	

			End Forall	

		Next			

	End If		

End Forall



Exit Sub	

ProcessError:

Continue = False

Message = "Error (" & Cstr(Err) & "): " & Error$ & " on line " & Cstr(Erl) & " in Control Agent\Update Location Name Agent."

Call ErrorDisplay(Message, NotesOrWeb(0))

Exit Sub	

End Sub

Thanks a million!

Dan

Subject: RE: db.Search Formula help

searchFormula = {Form = “} + formName + {” & } + fields + { = “} + locationOriginal {”}

Subject: RE: db.Search Formula help

Thanks a million!!

I was really out of it today…

Thanks!

Dan

Subject: RE: db.Search Formula help

Hi, In my case if the LocationOriginal is a multi value text list field, how do i access it’s values in the search formula?

I tried using NotesItem class and then item.values but it gives me type mismatch.

Here’s my code:

Set Keywordview = db.GetView(“(Keywords)”)

Set  keyworddoc = Keywordview.GetDocumentByKey("FilterSet")



If Not keyworddoc Is Nothing Then

	Set Filterset= keyworddoc.GetFirstItem( "Values" )

End If



searchFormula$ = {Form = "GHRDB" & EMPL_STATUS = "} + Filterset.values + {"}

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

Please advise asap.

Thanks in advance

Sonal