I’m developing a script that checks the name of an attached file in a RT lite field. The formulary must be saved when this file has a .pdf extension only. I made this script works, but when we run this script I get this error “TYPE MISMATCH IN METHOD FORALLINT, FROMVAR FOUND, UNKNOW EXPECTED”, when we start the Forall Loop.
I looked for solutions on internet, but there are so few explanations about this error.
I hope that someone can help me…
Any answer will be appreciated.
Here’s the code:
Dim session As New NotesSession
Dim wks As New NotesUIWorkspace
Dim db As NotesDatabase
Set db = session.currentDatabase
Set uidoc = wks.CurrentDocument
Dim doc As NotesDocument
Set doc = uidoc.document
Dim rtitem As Variant
Set rtitem = doc.GetFirstItem("proposta")
If (rtitem.Type = RICHTEXT) Then
Forall o In rtitem.EmbeddedObjects
If (o.Type = EMBED_ATTACHMENT) Then
Msgbox o.source
Dim smtpAddress As String
smtpAddress = o.Source
If smtpAddress <> "" Then
If Not smtpAddress Like "*.pdf" Then
Msgbox "Insira um arquivo com extensão .pdf!"
Call o.remove
Exit Sub
End If
End If
End If
End Forall
End If
Then you can check what rtitem looks like, and see if you have any attachments/embedded objects, and check the values of the different objects/variables.
I copied and pasted your code into a test database, and it worked fine, I did not get that error message (using Notes 8.5.3).
A couple of suggestions:
I would declare all variables in the beginning, before you execute any code or assign variables/objects. It is just so much easier to read when you have all declarations in one place.
In addition, you are using a variable called smtpAddress, but it is not used for that purpose, but to hold the name of the attachment. Use descriptive names for variables.
I personally use the convention to always name fields using CamelCase, not all lower case like you do. And even if the field name in GetFirstItem() is case-insensitive, I make sure I capitalize the field name exactly like it is on the form.
Finally, a suggestion that is really not for you, but your posting reminded me about it: I suggest that everyone use english variable names and (if possible) form names. That will make it easier for anyone that need help here in the forums.
If you post in Spanish, Portugese, Swedish or any other language than English, you will automatically cut down the number of people who will understand your posting or your code.
So for anyone who want as many responses as possible, make it easy for everyone to read the code (and posting).
Thanks for your tips! I’ll pay more attention when I translate the code to English,for better understanding.
I used the debugger, and all still the same. The error appears at the start of the forall loop, and seems to have no variant or other thing wrong.
You said that the code ran correctly in your test database, but on mine database the code didn’t work.
As I said previously, I surfed on web and nothing like this error was found to help me.
One thing that I noticed is, this error not occurs everytime. Sometimes the code runs as it must be, on the other hand I get no result. It occurs often when I use the debbuger.