문제

I want to capture error message in error handler and use it in if condition:

errorhandler:
Print "Error in function TriggerMail -- " & Cstr(Error) &  " -- occured at line - " & Cstr(Erl())   
MsgBox CStr(Error)

    If CStr(Error) = "Unable to send mail, no match found in Name & Address Book(s)" Then
        curdoc.Flag = " Invalid Short name"
                Call curdoc.Save(False, True)
             end if

I am using cstr(Error) which I got and and validtaing...Though my 'If' condition is true it is skipping the condition.

Please correct me and tell me some alternative way.

Tried using error number still not able to get into if loop

Call doc.Send(False, False)

    If Str(Err) = "4294" Then
        curdoc.Flag = " Invalid Short name"
        curdoc.defaulterSLACount = CInt(defaultCount)
        Call curdoc.Save(False, True)
    Else
''---------------------------------------------------------------------------------------------------------------   
' Flags set in the week doc of the defaulter for reference  
    'curdoc.Flag = "Mail Sent Successfully"
    curdoc.SentTo = doc.sendTo
    curdoc.CopiedTo = doc.CopyTo
    curdoc.SentOn = Cstr(Now)
    curdoc.defaulterSLACount = Cint(defaultCount)

    Call curdoc.Save(False, True)
    End If

Else

    curdoc.Flag = "Mail Not Sent"
    curdoc.defaulterSLACount = Cint(defaultCount)
    Call curdoc.Save(False, True)

End If  ' --------------------  DefaulterCount If Check ends here

Exit Function

errorhandler:
Print "Error in function TriggerMail -- " & Cstr(Error) &  " -- occured at line - " & Cstr(Erl())   
MsgBox Str(Err)

Resume Next
도움이 되었습니까?

해결책

Rather than using Error I would suggest you to use Err statement to get the error number and depending on it perform your action.

Update:

You need to write your condition If Str(Err) = "4294" Then inside the error handler.

errorhandler:

    If Str(Err) = "4294" Then
        curdoc.Flag = " Invalid Short name"
        curdoc.defaulterSLACount = CInt(defaultCount)
        Call curdoc.Save(False, True)
    Else

Or you could write code to handle error specifically for 4294

... 
... 
... 
On Error 4294 goto AmbiguousError doc.send(True) 
... 
... 
... 
Exit sub 

AmbiguousError: 
Set namesdb= session.getdatabase(db.server, "names.nsf") 
Set Persondoc= namesdb.getview("($Users)").getdocumentbykey(docmail.SendTo(0)) 
docMail.SendTo = Persondoc.fullname(0) & "@" & Persondoc.MailDomain(0) 
Call docMail.Send(True) 
Resume next 
End sub 

The above code snippet was taken from this TechNote.

다른 팁

Better use the On Error statement as it's meant to be used:

On Error number Goto handler

At the start of the function, you can already specify how you want to catch your errors.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top