Db.search with date

Hi,My db.search doesn’t found any doc in my collection but I have some…

when I use script without date in my query is found all doc.

But not when i add a Date value

Here the code

Dim collection As NotesDocumentCollection

Dim selection As String

Dim jourType As New NotesDateTime (CurDoc.Jour(0))

Dim jourDate As String

jourDate = jourType.DateOnly



selection = |Form = "Reservation" & @Contains(ResourceName;"| & salleDemande & |") & @Left(ReserveDate;10)= [| & Format(jourDate,"dd/mm/yyyy") &|]|



Set collection = db.Search( selection, Nothing, 0 )



Msgbox  "Salle: " & salleDemande & Chr(13) & "Jour: " & Jour & Chr(13) & Chr(13) & "Sélection: " & selection & Chr(13) & Chr(13) & "Salle: " & salleDemande & Chr(13) & Str(collection.Count)

End Sub

The ReserveDate value (from resrc7.ntf) has the format

dd/mm/yyyy HH:MM:SS AA TZ

like: 17/04/2008 09:00:00 AM EDT

Any sugg… Thanks

Subject: RE: db.search with date

The ReserveDate is probably a date item. Date items do not have a format. It does not have the format dd/mm/yyyy. It does not have any format. You cannot use @Left(ReserveDate; 10) because @Left requires a text argument and ReserveDate is not text. There is no first character of ReserveDate because it does not contain any characters.

I think what you want is something more like this:

selection = |Form = “Reservation” & ResourceName = “| & salleDemande & |” & ReserveDate = [| & Format(jourDate,“Short Date”) &|]|

Do not use dd/mm/yyyy or your code will only work correctly in environments that use that formatting by default.

Incidentally, this is not a very good way to search by date. It would be faster to use a view sorted by room name and date, and use view searching functions to locate the records that match the two keys.

Subject: RE: db.search with date

thanks Andre for sugg and comments…

Your code doesn’t work for me (collection.count = 0) and I have 2 doc for the date asked.

Here What I need to do…

I create a new BD with a form who user select a Room (SalleDemande) and a date (jour). (ex: today)

When the user click on button, the code search on Resource & Reservation db to locate Room and date… I put it on a NotesCollection to print the infos list (hours, creator, purpose, etc.) on a NotesRichText Field (Body) and then the user can print the list infos about the Reserved Room.

it’s that a good way to do with db.Search for that?

My db doesn’t have any view (may be I need to create folder and search on it)

We have 7 rooms and each of them have between 150 to 800 reservation in R&R db. If I create a collection about view I can only put one query in my search… and then I need to re-loop for a second query… (it’s that really a faster way?)

Any suggs will be appreciated

Thanks

Subject: RE: db.search with date

Your code doesn’t work for me (collection.count = 0) and I have 2 doc for the date asked.

You could do some debugging to find out why. Instead of passing the value of your computed search directly to the Search method, store it in a variable, and use the debugger to view the value of that variable. Does it look correct? If you copy it to the clipboard and put it as the selection formula of a view in the resource database, does it select any documents? Possibly you should remove the call to Format altogether.

it’s that a good way to do with db.Search for that?

Not really, no. It seems like you might want to use an embedded view instead, and use the single-category formula to make it show the right documents.

If I create a collection about view I can only put one query in my search…

Not true. If a view is sorted by two columns, you can use a two-element array as your key and search for the documents that match both keys.

Dim keys(1)

keys(0) = RoomName

set keys(2) = curdoc.getfirstitem(“Jour”).DateTimeValue

something like that.

Whatever you do, you have to make sure the datatypes of your keys match the datatypes of whatever you’re trying to match them to. Don’t try to compare a string to a date value – they are not equal.

Subject: RE: db.search with date

Andre’s code works for me. I have two date fields that a user can use to restrict search results (DateCreatedFrom and DateCreatedTo). The button code below is working just fine. (searchStr could have been built in one statement, but I was struggling to find a typographical error.)

Sub Click(Source As Button)

Dim session As New notessession

Dim db As notesdatabase

Set db = session.CurrentDatabase

Dim doc As notesdocument

Dim ws As New NotesUIWorkspace

Set doc = ws.CurrentDocument.Document	



Dim searchStr As String

searchStr = |Form="Request"|

If doc.DateCreated(0) <> "All" Then

	searchStr = searchStr + | & DateCreated >= [|

	searchStr = searchStr + Format(doc.DateCreatedFrom(0),|Short Date|)

	searchStr = searchStr + |]|

	searchStr = searchStr +  |& DateCreated <= [|

	searchStr = searchStr + Format(doc.DateCreatedTo(0),|Short Date|)

	searchStr = searchStr + |]|

End If



Dim dc As NotesDocumentCollection

Set dc = db.Search(searchStr, Nothing, 0)

Msgbox dc.Count

End Sub