Type Mismatch error

Hello all.  I am trying to evaluate documents in a notes collection.  I need to look at two fields on the document in the notes collection to determine if I need to send a notification out.  One is a date field, and the other is a text field.  
I am getting an error when the two values are attempting to compare to each other.  

Sub Initialize
     Dim session As New NotesSession
     Dim db As NotesDatabase
     Dim collection As NotesDocumentCollection
     Dim view As NotesView
     Dim selection As String
     Dim doc As NotesDocument
     Dim StatusCheck As Variant
     Dim DateCheck As Variant
     Dim vartest As Variant
     Dim Memo As NotesDocument
     Dim Body As NotesRichTextItem
     Dim rtitem As NotesRichTextItem
     Dim richStyle As NotesRichTextStyle
     Dim NextOARF As String
     Dim NewReq As Variant
     
     Set db=session.CurrentDatabase
     Set view=db.GetView("OARF Processing Queue")
     
     Set doc = view.GetFirstDocument()
     
     NewReq="New Request"
     StatusCheck=doc.GetItemValue("txtStatus")
     DateCheck=doc.GetItemValue("txtMaturityDate")
     
(FIRST ERROR IS HERE!)  Type mismatch error.
     If StatusCheck<>NewReq Then
          Goto MoveOn
     End If
     Do


(I am guessing it will also hit an error here, but have not gotten that far yet.)          
          vartest=DateCheck-Date()
         
          If vartest>14 Then
               Set memo = s.currentdatabase.CreateDocument
               If memo Is Nothing Then
                    SendError = "SendNotification:  Unable To Assign Memo"
                    ErrorOccurred = True
               End If
               
               Set Body = memo.CreateRichTextItem("Body")
               If Body Is Nothing Then
                    SendError =  "SendNotification:  Unable To Assign Body"
                    ErrorOccurred = True
               End If
               
               Set richStyle = s.CreateRichTextStyle
               If richStyle Is Nothing Then
                    SendError = "SendNotification:  Unable To Assign RichTextStyle"
                    ErrorOccurred = True
               End If
               
               richStyle.NotesFont = FONT_HELV
               richStyle.Bold = True
               richStyle.Underline = False
               richStyle.FontSize = 12
               richStyle.NotesColor = COLOR_BLACK
               Call Body.AppendStyle(richStyle)
               
               Call Body.AddNewLine(1)
               Call Body.AppendText("OARF Form submitted for your approval, please click on link above to view and approve or reject request.")
               
               richStyle.NotesFont = FONT_HELV
               richStyle.Bold = True
               richStyle.Underline = False
               richStyle.FontSize = 14
               richStyle.NotesColor = COLOR_RED
               Call Body.AppendStyle(richStyle)
               
               Call Body.AddNewLine(1)
               Call Body.AppendText("NOTE:  This is your second notification. Loan Services will not release collateral on paid loans until OARF form has been confirmed.")
               
               Set rtitem=New NotesRichTextItem(memo, "Body")
               memo.Principal = "CN=NE_GL Comml Paids/OU=GL/OU=KB/O=KeyCorp"
               memo.From = "CN=NE GL Comml Paids/OU=GL/OU=KB/O=KeyCorp"
               Call rtitem.AppendDocLink(doc,"OARF")
               memo.Subject = "Officer Acknowledgement Release Form"
               memo.SendTo=doc.FieldGetText("txtOfficerEMail")
               Set Status=doc.ReplaceItemValue("txtStatus","Second Request")
               Call memo.Send(False)
               
MoveOn:
               Set doc = view.GetNextDocument(doc)
          End If
     Loop
End Sub
pucktarget2Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
HemanthaKumarConnect With a Mentor Commented:
Similarly, DateCheck(0) will contain the value of the field. So to find the difference between two dates use this routine

Set dt1= New NotesDateTime( "Today" )
Set dt2 = New NotesDateTime( Datecheck(0) )
diff = Abs(dt2.TimeDifference( dt1 ))
days = diff/86400
Print days

0
 
snocrossCommented:
Ok, assuming the text field contains an actual date (ie: "October 8, 1996") you could do something like this:

If StatusCheck<>DateValue(NewReq) Then
         Goto MoveOn
    End If

Can you try this and let me know what happens?
0
 
HemanthaKumarCommented:
Hello Puck,
GetItemValue will return the value in a array, if it is a single value the value will be refered at index 0, so your code becomes

  If StatusCheck(0) <> NewReq Then
         Goto MoveOn
    End If

~Hemanth
0
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
pucktarget2Author Commented:
I can get past the New Request eval.  Having trouble with the date.  It is pulling a null value from the field I am referencing on the form.  Can I pull the create date somehow?
0
 
pucktarget2Author Commented:
Thanks again for some good code hemanth.
0
 
pucktarget2Author Commented:
I get an "Function requires a valid ADT argument. " error when running this agent.

It happens at the end of the do just before the loop at this code:

Set doc = view.GetNextDocument(doc)
         
Thanks!
0
 
pucktarget2Author Commented:
I was able to fix the date value problem.

Puck
0
 
snocrossCommented:
You could use doc.created as in;

If StatusCheck<>doc.created Then
        Goto MoveOn
   End If
0
 
snocrossCommented:
Ok, disregard my comment then... a minute later..
0
 
snocrossCommented:
I think you need to change your DO statement to handle when there is no longer a document for example:

Do While not (Doc is Nothing)
0
 
pucktarget2Author Commented:
Thanks again Hemanth.  I am getting a little better at understanding notes code.  Quick follow-up.  Is my loop going to stop or will it know to exit once it reaches the end of the document collection.

Puck
0
 
HemanthaKumarCommented:
Your loop doesn't seem to handle the document = nothing exception

So you might have to put this block of script in a while loop like this

Set doc = view.GetFirstDocument

While not doc is nothing

............


' Do this block

............

Set doc = view.GetNextDocument(doc)
Wend



0
 
pucktarget2Author Commented:
Nothing seems to work.  I looks like it is not changing to a null value after hitting the last document so then it just keeps looping over the last document over and over again.

Puck
0
 
HemanthaKumarCommented:
Change the loop statement to check for the doc = nothing

DO
:
:
LOOP until doc is nothing
0
 
pucktarget2Author Commented:
Thanks Hemanth....using your Loop Until doc is nothing helped me find the problem.  Doc was never equaling nothing because the loop was going over the getnextdocument command from this point:

If days<>14 Then
               Set memo = s.currentdatabase.CreateDocument
               If memo Is Nothing Then
                    SendError = "SendNotification:  Unable To Assign Memo"
                    ErrorOccurred = True
               End If

It would skip to the end if after the set doc = view.getnextdocument. This meant is never read zero.  I changed it to this and it worked:

If days<>14 Then
               Goto MoveOn
          Else
               Set memo = s.currentdatabase.CreateDocument
               If memo Is Nothing Then
                    SendError = "SendNotification:  Unable To Assign Memo"
                    ErrorOccurred = True
               End If
0
 
pucktarget2Author Commented:
Hemanth.....I want to give you some extra point for the help.  Or do you just want me to make it up to you next time?

Thanks again.

Puck
0
 
HemanthaKumarCommented:
May be next time.

Thanks for the offer.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.