Type mismatch on db.Search

I’m having trouble with a db.Search returning “Type mismatch.” Here is the chunk of relevant code (the “Type mismatch” occurs on the final line):

Dim s As New NotesSession

Dim dealDoc As NotesDocument

Dim matchingDeals As NotesDocumentCollection

Set db = s.CurrentDatabase

Dim deal As String

Dim searchFormula As String

doAnother = True

While doAnother

deal = Inputbox("Enter Deal Nbr")

searchFormula = {(form = "DEALNew" | form = "DEALAmend" | form = "DEALInherit") & !@IsResponseDoc & (Status = "Pipeline" | Status = "Request" | Status = "Contract" | Status = "Proof" | Status = "Mailed") & (DealNbr = "} + deal + {")}

Set matchingDeals = db.Search(searchFormula, Nothing, 0)

I’ve tried the formula in a view, and it behaves as expected. When I look at the searchFormula String via Messagebox, everything looks fine. For example, if I enter KPPL-6U3NJ9 into the Inputbox, searchFormula shows up in Messagebox as follows:

(form = “DEALNew” | form = “DEALAmend” | form = “DEALInherit”) & !@IsResponseDoc & (Status = “Pipeline” | Status = “Request” | Status = “Contract” | Status = “Proof” | Status = “Mailed”) & (DealNbr = “KPPL-6U3NJ9”)

But it bombs out with a “Type mismatch” on db.Search. Anybody have any ideas on what I might be overlooking here? Thanks.

Subject: Type mismatch on db.Search

There’s no

Dim db as notesdatabase

I don’t know for sure, but I reckon that might be your problem - i guess the search can’t act on a variant

Dan

Subject: RE: Type mismatch on db.Search

No Dim db As NotesDatabase! Ouch–that’s what it was. Boy-oh-boy. I spent the better part of an afternoon messing with this! It’s always something dumb, eh? Thanks to everybody for the help! (As I shamefacedly back out the door . . .)

Subject: RE: Type mismatch on db.Search

To avoid problems like this always use Option Declare

You can set this in the programmer pane preferences so it’ll always be added when you create a new action/agent or whatever script. Then you wouldn’t have even been able to save the script, saving you a load of time.

Dan

Subject: Type mismatch on db.Search

I would wonder if the quotation marks are causing you problems when you feed it into the Search parameters. It doesn’t make sense, since your brackets should delimit those quotes, but I am not sure how Search works, so that would be where I would start. The examples in the documentation are not as nearly complex as what you have here…

brandt

Subject: RE: Type mismatch on db.Search

Thanks for the response. The thing is is that I have an even more complex db.Search in another agent that works without a hitch. Actually, the one that’s giving me trouble is an abbreviated version of the good one. Here’s the one that works:

searchFormula$ = {(form = “DEALNew” | form = “DEALAmend” | form = “DEALInherit”) & !@IsResponseDoc &

(Status = “Pipeline” | Status = “Request” | Status = “Contract” | Status = “Proof” | Status = “Mailed”)

& @IsMember(LenderSegment; @Explode(“} + LenderSegments(0) + {”; “,”))}

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

Subject: RE: Type mismatch on db.Search

Also, I’ve tried it as simply as this:

searchFormula = {form = “DEALNew”}

Set matchingDeals = db.Search(searchFormula, Nothing, 0)

and STILL it bombs out with “Type mismatch”

Subject: RE: Type mismatch on db.Search

Can you post the whole script? There are obviously missing pieces we aren’t seeing here.

brandt

Subject: RE: Type mismatch on db.Search

Sure, here it is. (In case you spot something goofy beyond the db.Search, I haven’t been able to debug that far into it yet.)

Sub Initialize

Dim s As New NotesSession

Dim dealDoc As NotesDocument

Dim matchingDeals As NotesDocumentCollection

Set db = s.CurrentDatabase

Dim deal As String

Dim searchFormula As String



doAnother = True



While doAnother

	deal = Inputbox("Enter Deal Nbr")

	'find the deal

	searchFormula = {(form = "DEALNew" | form = "DEALAmend" | form = "DEALInherit") & !@IsResponseDoc & (Status = "Pipeline" | Status = "Request" | Status = "Contract" | Status = "Proof" | Status = "Mailed") & (DealNbr = "} + deal + {")}

	Set matchingDeals = db.Search(searchFormula, Nothing, 0)

	

	'Check that only one doc has been retrieved:

	makeChange = True

	If matchingDeals.Count > 1 Then

		Messagebox "Check for duplicates of deal # " & deal & ".  No change made."

		makeChange = False

	Elseif matchingDeals.Count = 0 Then

		Messagebox "No match found for deal # " & deal

		makeChange = False

	End If

	If makeChange Then

		Set dealDoc = matchingDeals.GetFirstDocument

		daysInProg% = Cint(Inputbox("Enter Days In Prog"))

		If dealDoc.Status(0) = "Pipeline" And Isdate(dealDoc.PipelineDate(0)) Then

			dealDoc.PipelineDate = Date() - daysInProg%

			Call dealDoc.Save(True,True)

		Elseif  Isdate(dealDoc.NegEndDate(0)) Then

			dealDoc.NegEndDate = Date() - daysInProg%

			Call dealDoc.Save(True,True)

		End If

	End If

	'see if user wants to change another:

	boxType& = MB_YESNO + MB_ICONQUESTION

	answer% = Messagebox("Do you want to continue?", boxType&, _ 

	"Continue?")

	If answer% = IDNO Then

		doAnother = False

	End If

Wend

End Sub

Subject: Type mismatch on db.Search

This may be relevant:

RESOLVED - http://www-10.lotus.com/ldd/46dom.nsf/DateAllThreadedweb/bcec50a026711a368525700500078cdd?OpenDocument