How come my code below comes up w/ a type mismatch error? I want to grab the numeric value from a field in another form (I’ve tried to make the field both a number and text) and reduce it by 500. Then put the new value back into the field. What am I missing here?
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim db As NotesDatabase
Dim view As NotesView
Dim uiView As NotesUIView
Dim collection As NotesDocumentCollection
Dim doc, doc2 As NotesDocument
Dim item As NotesItem
Dim Sendto1, n As Variant
Dim p As Integer
Set doc2 = db.GetDocumentByUNID("B1AE2B1EAE877EF88525703100597337")
n = doc2.GetItemValue("BCCount")
p = Cint(n)
n = (n - 500)
Call doc2.ReplaceItemValue("BCCount", n)
Subject: Type Mismatch Error
Which line is getting the error?I am betting the problem is when you subtract 500. You converted p to an integer, but you never converted n.
Subject: RE: Type Mismatch Error
I get the error when trying to convert using the CInt. I tried the CInt function in the line you see below and also previously in the GetItemValue line. Both places it gives the type mismatch error. Based on the code you see how would you modify it to work around this error? The BCCount field is currently a number field but has been text as well. What do you recommend?
Set doc2 = db.GetDocumentByUNID(“B1AE2B1EAE877EF88525703100597337”)
n = doc2.GetItemValue(“BCCount”)
p = Cint(n)
n = (n - 500)
Call doc2.ReplaceItemValue(“BCCount”, n)
Subject: Type Mismatch Error
be careful with your dim statements. When you do Dim doc, doc2 as NotesDocument, you are actually defining:
Dim doc as Variant
Dim doc2 as NotesDocument.
What you need to do is dim doc as NotesDocument, doc2 as NotesDocument.
And the other responder is correct. You have n defined a Variant and are trying to do arithmetic with it.
Assuming BCCount item is of type Number, you need to know if
BCCount will exceed +/-32,768. If so, change to p as Long (and Clng(n) ).
p = Cint(n) - 500
call doc2.ReplaceItemValue(“BCCount”,p)
Subject: RE: Type Mismatch Error
The type mismatch is for sure in the p = (Cint(n) - (count * 500)) line.
Ths field that the n field pulls from is a number field.
Here is my code thus far:
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim db As NotesDatabase
Dim view As NotesView
Dim uiView As NotesUIView
Dim dc As NotesDocumentCollection, dc2 As NotesDocumentCollection
Dim doc As NotesDocument, doc2 As NotesDocument
Dim item As NotesItem
Dim Sendto1 As Variant, n As Variant
Dim count As Integer, p As Integer
Set dc2 = db.UnprocessedDocuments
count = dc2.Count
Set doc2 = db.GetDocumentByUNID("B1AE2B1EAE877EF88525703100597337")
n = doc2.GetItemValue("BCCount")
p = (Cint(n) - (count * 500))
Call doc2.ReplaceItemValue("BCCount",p)
’ Call doc.Send(True, Sendto1)
Set doc = dc.GetNextDocument(doc)
Subject: RE: Type Mismatch Error
ok. time to punt. I don’t trust the GetItemValue method very often. use the shortcuts and change values to long.
dim n as long
n = CLNG(doc2.BCCount(0) )
doc2.BCCount = n - (count * 500)
i think you have omitted some code for brevity?
you have not set the dc doc collection but are using it in a loop. you have set dc2 as unprocessed docs but are are not using it in the loop. Also db is not set, and
Is this a correct assumption?
set db = session.currentDatabase
set dc2 = db.UnprocessedDocuments
count = dc2.Count
set doc = dc2.getFirstDocument
while not doc is nothing
set doc2 = db.getDocumentByUNID(…)
n = CLNG(doc2.BCCount(0) )
doc2.BCCount = n - (count * 500)
call doc2.save(true,false)
call doc2.Send(True,Sendto1)
call session.UpdateProcessedDoc(doc)
set doc = dc2.getNextDocument(doc)
wend
Subject: RE: Type Mismatch Error
one other thing …What is in the field?
You have never said whether you know that you are actually getting a numeric value in the field that you are accessing. If you are hitting a document with a bad text value, you will not be able to do math functions.
Subject: RE: Type Mismatch Error
Here is all the code. I’ve tried pulling from a number and text field. It has an error for both. Thanks for your help.
Sub Click(Source As Button)
’ this e-mails selected documents to names selected from an address dialog
Dim session As New NotesSession
Dim workspace As New NotesUIWorkspace
Dim db As NotesDatabase
Dim view As NotesView
Dim uiView As NotesUIView
Dim dc As NotesDocumentCollection, dc2 As NotesDocumentCollection
Dim doc As NotesDocument, doc2 As NotesDocument
Dim item As NotesItem
Dim Sendto1 As Variant, n As Variant
Dim count As Integer, p As Integer
’ Dim item As NotesItem 'this is for send history
Dim ItemB As Notesitem ' get position field value for subject line
Set db = session.CurrentDatabase
Set uiView = workspace.CurrentView
Set dc = uiView.Documents
Set doc = dc.GetFirstDocument
If doc Is Nothing Goto ErrorMessage
Sendto1 = (Inputbox$("Enter the e-mail address you'd like to send this off to."))
’ Sendto1 = workspace.Pickliststrings(PickList_Names)
While Not (doc Is Nothing)
Set itemB = doc.getfirstitem("Position")
doc.subject = "New Business Card Order "
Set dc2 = db.UnprocessedDocuments
count = dc2.Count
Set doc2 = db.GetDocumentByUNID("B1AE2B1EAE877EF88525703100597337")
n = doc2.GetItemValue("BCCount")
p = (Cint(n) - (count * 500))
Call doc2.ReplaceItemValue("BCCount",p)
’ Call doc.Send(True, Sendto1)
Set doc = dc.GetNextDocument(doc)
Wend
Msgbox "Selected documents have been sent"
Exit Sub
ErrorMessage:
Msgbox " You have not selected any documents. Place a check mark next to a document to select it"
End Sub