Search formula for DB.Search

I want to search for those documents in database which were created using either of the two forms, say, Form1 and Form2 and also where a field called MyField in both the forms contain the value I specify at runtime. How can I create a search formula for the above criteria to be used in Db.Search method? Pl help.

Subject: Search formula for DB.Search

Dim formula as Stringformula = {( (form = “Form1”) | (form = “Form2”) ) & (MyField = “} + YourRunTimeValue + {”)}

I assumed your run time value is of type String.

I hope this helps you.

Subject: RE: Search formula for DB.Search

I know this is little bit of an older thread, but I am basically trying the same thing. I’m trying to compare based on form type (works) and a datetime field comparing to a datetime object in my code (doesn’t work).

Here is my search formula:

Dim dtTestDocDateTime As New NotesDateTime(CurrentDoc.ActionDate(0))

searchString$ = {(Form = “Salary History”) & (ActionDate = dtTestDocDateTime)}

Where ActionDate is a date time field in the documents I’m searching through, and CurrentDoc is the document that’s calling the code from the querysave event.

When I run it like this I get a collection with count of 0, but there should be 5 documents that this pulls up. I’ve run through debug and dtTestDocDateTime gets the correct date.

So what am I doing wrong?

crr

Subject: RE: Search formula for DB.Search

Ok, I solved this one, and it works, sorta. I basically needed to call the value property of the NotesItem in question. Basic mistake, I know…silly me to think that a DateTime object would equivilate to a DateTime field.

At any rate, that works technically, but exposed a logical error in that I also need to be able to catch data that’s been entered in a changed doc rather than just a new one, so I need to access the UIDoc instead.

So, when trying to access the UIdoc value I go about it thusly:

    Dim dcThisDate As notesDocumentCollection

Dim docTestDoc As notesdocument

Dim searchString As String

Dim TestDocDateTime As String



testDocDateTime$ = source.fieldgettext("ActionDate")

searchString$ = {(Form = "Salary History") & (ActionDate.Text = testDocDateTime)}



Set dcThisDate = DB.Search(searchString$, Nothing, 0)

Where source is the UIDoc in question and ActionDate is a field in the Salary History form.

Now then, assuming I open an existing doc in the db, change the ActionDate field value and save the doc, I should either get a) a successful save or b) an error based on the fact the the ActionDate and Employee number are the same as an existing doc. The code above works with a new doc, but not when I edit an existing one.

Running debug I can see that the value of testDocDateTime is being set correctly (i.e. to whatever I change it to in the UIdoc) but the doc collection that results is showing a count of 5 when I enter a date (such as today) where there are no docs that have that value in the ActionDate field.

Can someone point me in the correct direction on this one?

Thanks,

crr

Subject: RE: Search formula for DB.Search

Hi, How to write the search formula if the “YourRunTimeValue” field is a multivalue field?

Please advise asap.

Thanks

Sonal

Subject: RE: Search formula for DB.Search

Convert it to a string and use Join to make a list from it:

… & MyField=“} & Join(YourRunTimeStringValue,{”:“}) & {”}

Subject: RE: Search formula for DB.Search

Thanks so much…U r a life saver.

It works great!!!

Sonal

Subject: RE: Search formula for DB.Search

Thanks, it worked.