Code to insert attachment in email (Access)

michane

Registered User.
Local time
Tomorrow, 03:01
Joined
Feb 25, 2013
Messages
26
[SOLVED] Code to insert attachment in email (Access)

Hi guys, I've been stuck with this for very long, searching everywhere to no avail.. I'm using an Attachment box on my access form. And I'm working on coding that can allow me to open outlook with clicking a button & the address, attachment etc. should be filled in. I've gotten the email part, however, i am having problem putting the attachment in the email.
Currently this is what I have for the attachment part,

Code:
    Dim i As Integer

    'The following code is for counting the number of attachment:

    If Scan_Doc.AttachmentCount() > 0 Then
        For i = 0 To Scan_Doc.AttachmentCount() - 1
    
            'Adding each attachment
            mailItem.Attachments.Add (Dir(Scan_Doc.FileURL(i)))
   
        Next
    Else
    MsgBox "There are no attachments - Please check.."
    End If

**Scan_Doc is the name i use for the Attachment control.

The problem is, when i insert debug on the line Scan_Doc.FileURL(i), it keep showing that the string is empty, even with 1 attachment count!

Can someone help me see what is the problem here :confused:
 
Last edited:
Manage to solve it by doing the hard way :

Code:
    Dim i As Integer
    Dim fileName As String
    
    'The following code is for adding of attachment , the path is right after the "mailItem.Attachments.Add"
    If Scan_Doc.AttachmentCount() > 0 Then
        For i = 0 To Scan_Doc.AttachmentCount() - 1
        fileName = Scan_Doc.fileName(i)
        
        If cmbSupplier.Value = "0" Then mailItem.Attachments.Add ("...\" & fileName)
        If cmbSupplier.Value = "1" Then mailItem.Attachments.Add ("...\" & fileName)
        'Continue for the rest of the items in the combobox (cmbSupplier)...
        Next
    Else
    MsgBox "There are no attachments - Please check.."
    End If
 

Users who are viewing this thread

Back
Top Bottom