Email Attachment Field

steve21nj

Registered User.
Local time
Today, 02:22
Joined
Sep 11, 2012
Messages
260
I have a small/simple database, using the attachment field to actually store attachments rather than hyperlinking to a shared location. I know I'll get some slack for that, but the database itself will remain rather small until we move the database to a sharepoint server.

In the mean time, my question is, is there a way to send an email and attach the attachment.value(s) directly to the email automatically? Where it would identify if 0 -9 attachments existed and automatically attached to the email.

I've seen code based on a shared drive location, or local computer, but not to the field value directly.
 
I've got an example with Lotus Notes I could share. What email are you using?
 
Using outlook!
 
On the below I get a run-time error '-214735256
Cannot add the attachment; no data source was provided.

How or where do I reference the underlined area to pull the attachment field's data?

Code:
Private Sub Command6311_Click()
    Dim objOL As New Outlook.Application
    Dim objMail As MailItem
    Set objOL = New Outlook.Application
    Set objMail = objOL.CreateItem(olMailItem)
 
    msg = Nz(Me.[FITitle], "")
    bdy = "In reference to request " & Nz(Me.[FITitle], "")
    CC = ""
 
    With objMail
        .To = CC
        .Subject = msg
        .Body = bdy   
       [U][COLOR=black].Attachments.Add (strAttachementPath)[/COLOR][/U]
        .Display
 
    End With
 
    Set objMail = Nothing
    Set objOL = Nothing
End Sub
 
What is strAttachementPath? You have not defined it anywhere in the Code? In other words, where do you want the file to be picked up from?
 
From the attachment field labeled [my attachment].value

That field can have multiple attachment. Wondering how I could attach all attachments associated to the record ID.
 
Still cannot see [my attachment].value in the above code.. Is that an Attachment type? Or just path to the files?
 
Its the data type in the table, instead of using a text field, I'm using the attachment field type.

This is only temporary (6 months) until the database is built in SharePoint.
 

Attachments

  • attachment.PNG
    attachment.PNG
    2.5 KB · Views: 202
Last edited:
So I basically figured out what I needed. I am getting an error on the attachment part saying it cannot attach the folder to the email. Is there a way around this or a way to grab all the files in that folder and automatically attach them in the email generated?

Code:
Private Sub Command6311_Click()
    Dim objOL As New Outlook.Application
    Dim objMail As MailItem
    Set objOL = New Outlook.Application
    Set objMail = objOL.CreateItem(olMailItem)
 
   Dim strRFIitems As String
    ' Define in one place, use in three.
    strRFIitems = "C:\Desktop\" & Me.NumberTP
 
 
 
    msg = Nz(Me.[RFI], "")
    bdy = "In reference to request " & Nz(Me.[RFI], "")
 
    CC = ""
 
    With objMail
        .To = CC
        .Subject = msg
        .Body = bdy
        If Len(Dir(strRFIitems, vbDirectory)) = 0 Then
        'Nothing
        Else
        .Attachments.Add (strRFIitems)
        End If
 
        .Display
 
    End With
 
    Set objMail = Nothing
    Set objOL = Nothing
End Sub
 
For anyone looking for something similar, I changed my thought process and removed the attachment field all together.

I added a button the form that created a folder to set location that I could store my info and have the folder open when I send my email so I can attach whatever files I wish.

Me.RFI refers to a unique field name. So the folder is created as this unique name.

Adding on to the email code above, it looked like this:
Code:
End With
 
    Set objMail = Nothing
    Set objOL = Nothing
 
   strRFIitems = "C:\Desktop\" & Me.RFI
   If Len(Dir(strRFIitems, vbDirectory)) = 0 Then
        'Nothing
    End If
    Shell "EXPLORER.EXE " & strRFIitems, vbNormalFocus
 

Users who are viewing this thread

Back
Top Bottom