Error when sending lotus notes mail from vb5 application (MAPI controls)

kahvedzic used Ask the Experts™
When I try to send LN mail from Visual Basic 5 application I get an error message
Run-time error '7225'
File  not found (notice double space here)
After click on debug I get that error is in this line of code:
Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment" & Format(i, "#"))
This line is part of this code:

This application is from VB 5 and data for lotus notes mail is loaded from sql server to VB form.
Any idea why is this happening and how to solve this problem so I can send mails without this message.

Public Sub SendNotesMail(Subject As String, AttachmentG As String, Number As Integer, Recipient As String, BodyText As String, SaveIt As Boolean)
    Dim Maildb As Object ' mail database
    Dim UserName As String 'LN username
    Dim MailDbName As String 'notes mail database name
    Dim MailDoc As Object 'mail document
    Dim AttachME As Object 'attachment object
    Dim Session As Object 'notes session
    Dim EmbedObj As Object 'Attachment
    'Dim Recip(2) As Variant
    'SendTo1 = Trim(TextSendTo1)
    Recipient = SendTo
    'Recip(1) = SendTo1
    Set Session = CreateObject("Notes.NotesSession")
    'Session.Initialize ("passw")
    UserName = Session.UserName
    MailDbName = GbazaNSF
    Set Maildb = Session.GETDATABASE("", MailDbName)
     If Maildb.ISOPEN = True Then
          'Notes vec otvoren !!!
     End If
    Set MailDoc = Maildb.CREATEDOCUMENT
    MailDoc.Form = "Memo"
    MailDoc.SendTo = Recipient
    MailDoc.CopyTo = cc
    MailDoc.BlindCopyTo = bcc
    MailDoc.Subject = Subject
    MailDoc.Body = BodyText
    poz = 1
    poz1 = 1
    For i = 1 To Number
        poz2 = InStr(poz1, AttachmentG, ",")
        If poz2 = 0 Then
            poz2 = Len(AttachmentG) + 1
        End If
        Attachment = Mid(AttachmentG, poz1, poz2 - poz1)
        If Attachment <> "" Then
            Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment" & Format(i, "#"))
            Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment" & Format(i, "#"))
            'MailDoc.CREATERICHTEXTITEM ("Attachment")
        End If
        poz1 = poz2 + 1
    Next i
    MailDoc.PostedDate = Now()
    MailDoc.Send 0, Recipient
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set Session = Nothing
    Set EmbedObj = Nothing
End Sub

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I believe this line

Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment" & Format(i, "#"))

S/B something like

Attachment= "C:\ActiveSheet.xls"
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")

Since there is no reference to a file to attach?


sorry just read the code a little closer try this:

       Attachment = Mid(AttachmentG, poz1, poz2 - poz1)
       Attachment = Attachment & Format(i, "#")
        If Attachment <> "" Then
            Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")

I think you're going the wrong way now.
The memo should have a field of type richtext, called "body".
You could attach a file inside this body field.

In your original code,  MailDoc.Body = BodyText would create a body field populated with whatever text you supplied, but the field would be (normal) text. Normal text fields do not support attachments.

Without knowing too much of VB, the following could help you out:

Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment" & Format(i, "#"))

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

What exactly is the value of Attachment when you use it in .EMBEDOBJECT?
Would that explain the double space in the error message?
You need a valid path to the file that you want to attach there!


I have just tried and when I send LN mail without attachment get an error File  not found, but when I add an attachment mail is sent. If I comment line where debug shows error mail is sent but without any attachment. I guess what I need to do is to set attachME as "" if there is no attachment, but question is how to do that.
I think you just need to add the file..

        If Attachment <> "" Then
            Call Body.EMBEDOBJECT(1454, "", Attachment, "Attachment")
        End If

Also, take a look at this thread from IBM:

Just step through code and find out that the problem is on form Attachment has value " " and in code is If Attachment <> "" Then that is why I have error File not found. Just add Attachment<>" " and now works fine.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial