Email the files in the Attachment Field from Access 2007

J

Julie

Access 2007 - I have a form with an Attachment field. The user selects files
(Excel, Word etc) using this field and then I have a button to email these
files as attachments to Outlook.

Does anyone have code to do this?

Thank you
 
M

Mark Andrews

I do that in my application but it gets complex the way I do it because I
use an email template and an smtp component to send the emails.

I basically extract the file(s) from the attachment field and save them to a
directory called "Attachments999" and save the path in an array.
I expect 9 or less attachments in the attachments field.

Then you can just use a little bit of code to build an Outlook email. That
should be easy to find examples for.

HTH,
Mark

The code to retrieve the files from the attachment field is:
'Open recordset of attachments, save each one to disk and assign to
attachments() array
For iii = 1 To 9
Attachments(iii) = ""
Next iii
filepath = CurrentDBDir() & "Attachments999\"
If Len(Dir(filepath, vbDirectory)) = 0 Then
MkDir filepath
End If
iii = 1
Set RSAttachments = RS.Fields("Attachments").Value
While Not RSAttachments.EOF
If (FileExists(filepath &
RSAttachments.Fields("FileName").Value)) Then
Kill filepath & RSAttachments.Fields("FileName").Value
End If
RSAttachments.Fields("FileData").SaveToFile filepath
Attachments(iii) = filepath &
RSAttachments.Fields("FileName").Value
iii = iii + 1
RSAttachments.MoveNext
Wend
RSAttachments.Close


Function CurrentDBDir() As String

Dim strDB As String, strCurrentDir As String

strDB = CurrentDb.Name
strCurrentDir = Left(strDB, Len(strDB) - Len(Dir(strDB)))

CurrentDBDir = strCurrentDir
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top