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.
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 . . .)
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.
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…
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”)
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