Send email with attachment from attachment field (1 Viewer)

bruceblack

Registered User.
Local time
Today, 08:26
Joined
Jun 30, 2017
Messages
119
Hi Everyone!! I know this is somewhat a much about spoken subject. However every solution is find is not exactly how i want it. Some advise would be great :)

So i have my attachment field, but is there a way to just send it, instead of storing it on a drive first?

All other solutions save the attachment on the hard drive and then fetch it from there. I would like to NOT store it on a drive, since im on a closed off network.

Thanks in advance!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:26
Joined
May 7, 2009
Messages
19,169
You need to extract the attachment first, in your drive if you wish, then attach the physical file to your email.
 

bruceblack

Registered User.
Local time
Today, 08:26
Joined
Jun 30, 2017
Messages
119
Wow you were fast :). Thanks so much.

Good to know theres no other option. So i put something together:

There's a few problems with it i cant seem to figure out though :(.

1: When i want to send the email, and the folder it store the attachment in is empty, i get this:

The object type argument for the action or method is blank or invalid
DoCmd.OutputTo acOutputReport, strt1_customs, acFormatHTML, "H:\t1customs" & strt1_customs & ".HTML", False

When i close the error and send it again, it works and does send the mail all the sudden


2: After it's send, and i want to send a second time, it says object already exists. I coded it should empty the folder, but it somehow doesnt do that?


3: Big issue: It also picks up all the records from the query source.
I specifically say to use the current checklistID, but it ignores that?

DoCmd.OpenReport "t1_customs", acViewPreview, , "checklistID=" & Me.checklistID, acHidden



Here is my full code:

Option Compare Database

Private Sub send_Click()

Dim oFilesys, oTxtStream As Object
Dim txtHTML As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim OutlookAttach As Outlook.Attachment

Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)


DoCmd.OpenReport "t1_customs", acViewPreview, , "checklistID=" & Me.checklistID, acHidden

DoCmd.OutputTo acOutputReport, strt1_customs, acFormatHTML, "H:\t1customs" & strt1_customs & ".HTML", False
Set oFilesys = CreateObject("Scripting.FileSystemObject")
Set oTxtStream = oFilesys.OpenTextFile("H:\t1customs" & strReviewWorkOrdeMROR & ".HTML", 1)
txtHTML = oTxtStream.ReadAll
oTxtStream.Close
Set oTxtStream = Nothing

Set oFilesys = Nothing
Dim db As DAO.Database
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2
Set db = CurrentDb
Set rsParent = Me.Recordset
rsParent.OpenRecordset
Set rsChild = rsParent.Fields("shipattachment").Value

While Not rsChild.EOF
If Dir("H:\t1customs", vbDirectory) = "" Then
MkDir ("H:\t1customs")
Else
'do nothing for the "C:\dbtemp" directory already exists
'MsgBox "C:\dbtemp\ directory already exists"
End If

rsChild.OpenRecordset
rsChild.Fields("FileData").SaveToFile ("H:\t1customs")
rsChild.MoveNext
Wend

With MailOutLook
.bodyFormat = olFormatRichText
.To = "
bruce@logistics.com"
'.CC = " "
.Subject = "Expedition - T1 Inbound"
.HTMLBody = txtHTML
Dim fso As Object, SourceFolder As Object, SourceFile As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = fso.GetFolder("H:\t1customs")
For Each SourceFile In SourceFolder.Files
.Attachments.Add SourceFolder.Path & "" & SourceFile.Name
.Display
Next
'Send email
'.DeleteAfterSubmit = True 'This would let Outlook send the note without storing it in your sent bin
'.Send

Kill "H:\t1customs*.*" ' delete all files in the folder
RmDir "H:\t1customs" ' delete folder
End With
'MsgBox MailOutLook.Body
Kill " H:\t1customs" & strReviewWorkOrdeMROR & ".HTML"
'email_error:
'MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
'Resume Error_out
''Error_out:


End Sub
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:26
Joined
May 7, 2009
Messages
19,169
please see some modification i made

Code:
Option Compare Database

Private Sub send_Click()

Dim oFilesys, oTxtStream As Object
Dim txtHTML As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim OutlookAttach As Outlook.Attachment
Dim strFileName As String

Const PATH As String = "H:\t1customs\"

Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

DoCmd.OpenReport "t1_customs", acViewPreview, , "checklistID=" & Me.checklistID, acHidden

'
' agp
'
' you are missing a backslash on the folder name
' that is why it wasn't deleted
' when this sub exited
'
' create the PATH folder here first
If Dir(PATH, vbDirectory) = "" Then
    MkDir PATH
End If

DoCmd.OutputTo acOutputReport, strt1_customs, acFormatHTML, PATH & strt1_customs & ".HTML", False
Set oFilesys = CreateObject("Scripting.FileSystemObject")
Set oTxtStream = oFilesys.OpenTextFile(PATH & strReviewWorkOrdeMROR & ".HTML", 1)
txtHTML = oTxtStream.ReadAll
oTxtStream.Close
Set oTxtStream = Nothing

Set oFilesys = Nothing
Dim db As DAO.Database
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2
Set db = CurrentDb
Set rsParent = Me.Recordset
rsParent.OpenRecordset
Set rsChild = rsParent.Fields("shipattachment").Value

While Not rsChild.EOF
' we already check the folder above
' so i comment this out
'
' agp
'
''If Dir("H:\t1customs", vbDirectory) = "" Then
''MkDir ("H:\t1customs")
''Else
'''do nothing for the "C:\dbtemp" directory already exists
'''MsgBox "C:\dbtemp\ directory already exists"
''End If

''rsChild.OpenRecordset
'
' arnelgp
'
' save the original filename to variable
strFileName = rsChild.Fields("FileName")
rsChild.Fields("FileData").SaveToFile (PATH & strFileName)
rsChild.MoveNext
Wend

' dont forget to close what we opened
rsChild.Close
Set rsChild = Nothing


With MailOutLook
.bodyFormat = olFormatRichText
.To = "bruce.zwarts@cevalogistics.com"
'.CC = " "
.Subject = "Expedition - T1 Inbound"
.HTMLBody = txtHTML
Dim fso As Object, SourceFolder As Object, SourceFile As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = fso.GetFolder(PATH)
For Each SourceFile In SourceFolder.Files
.Attachments.Add SourceFolder.PATH  '& "" & SourceFile.Name (SourceFolder.Path contains the path+filename)
Next
' display it here after processing all attachments
.Display

' dont forget to close fso
Set SourceFile = Nothing
Set SourceFolder = Nothing
Set fso = Nothing

'Send email
'.DeleteAfterSubmit = True 'This would let Outlook send the note without storing it in your sent bin
'.Send

Kill PATH & "*.*" ' delete all files in the folder
RmDir PATH  '"H:\t1customs" ' delete folder
End With
'MsgBox MailOutLook.Body
'Kill " H:\t1customs" & strReviewWorkOrdeMROR & ".HTML"
'email_error:
'MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
'Resume Error_out
''Error_out:

End Sub
 

bruceblack

Registered User.
Local time
Today, 08:26
Joined
Jun 30, 2017
Messages
119
Wow...always surprised about the swift replys on this forum.
A 1000000 thanks my friend.

When i run this code is still get:

The object type arguemnt for the action or method is blank or invalid


When i ignore that and End the debugger and run it a second time i get:

Only files or objects can be attachments. H:\t1customs is a folder and cannot be attached.

Apparently it wants to attach the folder.
I also notice i have been very clear with some naming.
My folder is called t1customs, and my report is called t1_customs.

Sorry about that
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:26
Joined
May 7, 2009
Messages
19,169
Sorry too.
Chnge this:

Attachments.Add SourceFolder.PATH

To:


Attachments.Add SourceFile.PATH
 

bruceblack

Registered User.
Local time
Today, 08:26
Joined
Jun 30, 2017
Messages
119
No sorry's. You're saving my ass right now :). AND it works!
Getting better and better. I only have that first problem still.

The first time i hit the send button, it gives me an error, the second time it does send the email without a problem.

The object type arguemnt for the action or method is blank or invalid

DoCmd.OutputTo acOutputReport, strt1_customs, acFormatHTML, PATH & strt1_customs & ".HTML", False


I assume the html file belongs in the attachment in the email?


Again, thank you so much for helping.

 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:26
Joined
May 7, 2009
Messages
19,169
What does the variable strt1_customs holds
 

bruceblack

Registered User.
Local time
Today, 08:26
Joined
Jun 30, 2017
Messages
119
haha. I'm trying to figure that out. When i disable that part it gives me errors as well. Still searching for the problem, ill update when i find it.
 

bruceblack

Registered User.
Local time
Today, 08:26
Joined
Jun 30, 2017
Messages
119
update: it holds the report that goes into the body of the email.
Thats my actual report name.

I added a few new references in the editor.
I added:

Microsoft office infopath
Microsoft html object library

This resulted in another error:

The command or action "OutputTo" isnt available now
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:26
Joined
May 7, 2009
Messages
19,169
It is not defined in the sub, you should define it at the beginning of the sub.

strt1_customs="t1_customs"
 

bruceblack

Registered User.
Local time
Today, 08:26
Joined
Jun 30, 2017
Messages
119
Hi Arnelgp. I tried but now i get a new error.

"File not found"

Set oTxtStream = oFilesys.OpenTextFile(PATH & strReviewWorkOrdeMROR & ".HTML", 1)

i have no cluse whats going on :(

Option Compare Database
Private Sub send_Click()
Dim oFilesys, oTxtStream As Object
Dim txtHTML As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim OutlookAttach As Outlook.Attachment
Dim strFileName As String
strt1_customs = "t1_customs"
Const PATH As String = "H:\t1customs"
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
DoCmd.OpenReport "t1_customs", acViewPreview, , "checklistID=" & Me.checklistID, acHidden
'
' agp
'
' you are missing a backslash on the folder name
' that is why it wasn't deleted
' when this sub exited
'
' create the PATH folder here first
If Dir(PATH, vbDirectory) = "" Then
MkDir PATH
End If
DoCmd.OutputTo acOutputReport, strt1_customs, acFormatHTML, PATH & strt1_customs & ".HTML", False
Set oFilesys = CreateObject("Scripting.FileSystemObject")
Set oTxtStream = oFilesys.OpenTextFile(PATH & strReviewWorkOrdeMROR & ".HTML", 1)
txtHTML = oTxtStream.ReadAll
oTxtStream.Close
Set oTxtStream = Nothing
Set oFilesys = Nothing
Dim db As DAO.Database
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2
Set db = CurrentDb
Set rsParent = Me.Recordset
rsParent.OpenRecordset
Set rsChild = rsParent.Fields("shipattachment").Value
While Not rsChild.EOF
' we already check the folder above
' so i comment this out
'
' agp
'
''If Dir("H:\t1customs", vbDirectory) = "" Then
''MkDir ("H:\t1customs")
''Else
'''do nothing for the "C:\dbtemp" directory already exists
'''MsgBox "C:\dbtemp\ directory already exists"
''End If
''rsChild.OpenRecordset
'
' arnelgp
'
' save the original filename to variable
strFileName = rsChild.Fields("FileName")
rsChild.Fields("FileData").SaveToFile (PATH & strFileName)
rsChild.MoveNext
Wend
' dont forget to close what we opened
rsChild.Close
Set rsChild = Nothing

With MailOutLook
.bodyFormat = olFormatRichText
.To = "bruce.zwarts@cevalogistics.com"
'.CC = " "
.Subject = "Expedition - T1 Inbound"
.HTMLBody = txtHTML
Dim fso As Object, SourceFolder As Object, SourceFile As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = fso.GetFolder(PATH)
For Each SourceFile In SourceFolder.Files
.Attachments.Add SourceFile.PATH '& "" & SourceFile.Name (SourceFolder.Path contains the path+filename)
Next
' display it here after processing all attachments
.Display
' dont forget to close fso
Set SourceFile = Nothing
Set SourceFolder = Nothing
Set fso = Nothing
'Send email
'.DeleteAfterSubmit = True 'This would let Outlook send the note without storing it in your sent bin
'.Send
Kill PATH & "*.*" ' delete all files in the folder
RmDir PATH '"H:\t1customs" ' delete folder
End With
'MsgBox MailOutLook.Body
'Kill " H:\t1customs" & strReviewWorkOrdeMROR & ".HTML"
'email_error:
'MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
'Resume Error_out
''Error_out:
End Sub
 

bruceblack

Registered User.
Local time
Today, 08:26
Joined
Jun 30, 2017
Messages
119
Still the same problem :(

Can someone help me please? :banghead:

Drives me nuts.

Set oTxtStream = oFilesys.OpenTextFile(PATH & strReviewWorkOrdeMROR & ".HTML", 1)

It gives me the error? I dont even know what it's supposed to do.
All i know is that it doesnt run without it either. :(
 

bruceblack

Registered User.
Local time
Today, 08:26
Joined
Jun 30, 2017
Messages
119
This is my full code that i use. I have no idea anymore whats going on.



Option Compare Database
Private Sub send_Click()
Dim oFilesys, oTxtStream As Object
Dim txtHTML As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim OutlookAttach As Outlook.Attachment
Dim strFileName As String
strt1_customs = "t1_customs"
Const PATH As String = "P:\WISSEL\Expeditie\21- Data Expeditie"
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
DoCmd.OpenReport "t1_customs", acViewPreview, , "checklistID=" & Me.checklistID, acHidden

If Dir(PATH, vbDirectory) = "" Then
MkDir PATH
End If
DoCmd.OutputTo acOutputReport, strt1_customs, acFormatHTML, PATH & strt1_customs & ".HTML", False
Set oFilesys = CreateObject("Scripting.FileSystemObject")
Set oTxtStream = oFilesys.OpenTextFile(PATH & strReviewWorkOrdeMROR & ".HTML", 1)
txtHTML = oTxtStream.ReadAll
oTxtStream.Close
Set oTxtStream = Nothing
Set oFilesys = Nothing
Dim db As DAO.Database
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2
Set db = CurrentDb
Set rsParent = Me.Recordset
rsParent.OpenRecordset
Set rsChild = rsParent.Fields("shipattachment").Value

While Not rsChild.EOF
strFileName = rsChild.Fields("FileName")
rsChild.Fields("FileData").SaveToFile (PATH & strFileName)
rsChild.MoveNext
Wend

rsChild.Close
Set rsChild = Nothing

With MailOutLook
.bodyFormat = olFormatRichText
.To = "
bruce@logistics.com"
'.CC = " "
.Subject = "Expedition - T1 Inbound"
.HTMLBody = txtHTML
Dim fso As Object, SourceFolder As Object, SourceFile As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = fso.GetFolder(PATH)
For Each SourceFile In SourceFolder.Files
.Attachments.Add SourceFile.PATH
Next

.Display
Set SourceFile = Nothing
Set SourceFolder = Nothing
Set fso = Nothing

Kill PATH & "*.*"
RmDir PATH
End With

End Sub
 

June7

AWF VIP
Local time
Today, 00:26
Joined
Mar 9, 2014
Messages
5,423
Is there supposed to be a \ at end of:

Const PATH As String = "P:\WISSEL\Expeditie\21- Data Expeditie"

If so, posted code is dropping \. Post within CODE tags.

The Advanced post editor has an option to "Automatically parse links in text". Uncheck this to prevent dropping \ from text within quote marks when saving post. Will have to do this every time before saving post.


Should include Option Explicit in module header.

Where is strReviewWorkOrdeMROR declared and set?
 
Last edited:

bruceblack

Registered User.
Local time
Today, 08:26
Joined
Jun 30, 2017
Messages
119
Hi! Thanks for your swift reply :) very kind.

No, there was no / but now you mentioned it, it put one there.

Also added explicit in header.

With that line up there, I have no idea what its supposed to do, or how to declare it for that matter.

It ALMOST works.
 

June7

AWF VIP
Local time
Today, 00:26
Joined
Mar 9, 2014
Messages
5,423
Option Explicit forces declaration of variables. It will help with discovering misspelled variables in code.

ALMOST works means what - error message, wrong results, nothing happens?

Still don't know where strReviewWorkOrdeMROR is declared and set. The line with this variable is attempting to open a text file and set variable txtHTML with content of that file. Variable strReviewWorkOrdeMROR is supposed to hold the text file's name.

Error handler code can actually interfere with debugging. Learn how to debug code https://www.techonthenet.com/access/tutorials/vbadebug2010/debug01.php
 

bruceblack

Registered User.
Local time
Today, 08:26
Joined
Jun 30, 2017
Messages
119
Thanks June7!

It's driving me up an ABSOLUTE wall.
I NEEEED this to work and will NOT in ANY way possble.
I have been up with this problem for weeks and im at the end of my rope here.

I have no clue what im doing anymore.
All i wanted to do is send an email with the attachment save in my records.

Option Compare Database
Option Explicit

Private Sub send_Click()
Dim oFilesys, oTxtStream As Object
Dim txtHTML As String
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim OutlookAttach As Outlook.Attachment
Dim strFileName As String

Dim strt1_customs As String
Dim strReviewWorkOrdeMROR As String

Const PATH As String = "P:\WISSEL\Expeditie\21- Data Expeditie"
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)

DoCmd.OpenReport "t1_customs", acViewPreview, , "checklistID=" & Me.checklistID, acHidden
'
' agp
'
' you are missing a backslash on the folder name
' that is why it wasn't deleted
' when this sub exited
'
' create the PATH folder here first
If Dir(PATH, vbDirectory) = "" Then
MkDir PATH
End If

'DoCmd.OutputTo acOutputReport, strt1_customs, acFormatHTML, PATH & strt1_customs & ".HTML", False
Set oFilesys = CreateObject("Scripting.FileSystemObject")
'Set oTxtStream = oFilesys.OpenTextFile(PATH & strReviewWorkOrdeMROR & ".HTML", 1)
'txtHTML = oTxtStream.ReadAll
'oTxtStream.Close
Set oTxtStream = Nothing

Set oFilesys = Nothing
Dim db As DAO.Database
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2
Set db = CurrentDb
Set rsParent = Me.Recordset
rsParent.OpenRecordset
Set rsChild = rsParent.Fields("shipattachment").Value

While Not rsChild.EOF
' we already check the folder above
' so i comment this out
'
' agp
'
''If Dir("H:\t1customs", vbDirectory) = "" Then
''MkDir ("H:\t1customs")
''Else
'''do nothing for the "C:\dbtemp" directory already exists
'''MsgBox "C:\dbtemp\ directory already exists"
''End If

''rsChild.OpenRecordset
'
' arnelgp
'
' save the original filename to variable
strFileName = rsChild.Fields("FileName")
'rsChild.Fields("FileData").SaveToFile (PATH & strFileName)
rsChild.MoveNext
Wend

' dont forget to close what we opened
rsChild.Close
Set rsChild = Nothing


With MailOutLook
.bodyFormat = olFormatRichText
.To = "
bruce.zwarts@cevalogistics.com"
'.CC = " "
.Subject = "Expedition - T1 Inbound"
.HTMLBody = txtHTML
Dim fso As Object, SourceFolder As Object, SourceFile As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = fso.GetFolder(PATH)
For Each SourceFile In SourceFolder.Files
.Attachments.Add SourceFile.PATH '& "" & SourceFile.Name (SourceFolder.Path contains the path+filename)
Next
' display it here after processing all attachments
.Display

' dont forget to close fso
Set SourceFile = Nothing
Set SourceFolder = Nothing
Set fso = Nothing

'Send email
'.DeleteAfterSubmit = True 'This would let Outlook send the note without storing it in your sent bin
'.Send

Kill PATH & "*.*" ' delete all files in the folder
RmDir PATH '"H:\t1customs" ' delete folder
End With
'MsgBox MailOutLook.Body
'Kill " H:\t1customs" & strReviewWorkOrdeMROR & ".HTML"
'email_error:
'MsgBox "An error was encountered." & vbCrLf & "The error message is: " & Err.Description
'Resume Error_out
''Error_out:


End Sub
 

bruceblack

Registered User.
Local time
Today, 08:26
Joined
Jun 30, 2017
Messages
119
To clarify:

I do NOT have the intention to "make folders" or make them delete or have html docs attachted and what not.

All i want is to send the attachment field inside of a email. :banghead::banghead::banghead:
How difficult can this actually be?!?!?!!
 

June7

AWF VIP
Local time
Today, 00:26
Joined
Mar 9, 2014
Messages
5,423
First of all, as already pointed out, need to post code between CODE tags to retain indentation and readability and the \ character will not drop. USE CODE TAGS.

It is necessary to first extract embedded file to a folder before it can be attached to email. You have commented the line that saves file to folder.

I see you now have strReviewWorkOrdeMROR declared but where is it set? This variable is supposed to hold name of text file to be opened. This text file is used to populate variable txtHTML which is used as the message body. If you don't open the text file to populate txtHTML variable, what do you intend to use as the body of the message?

The procedure opens a report but the code to save it as HTML file is commented. This file is supposed to become the content of variable txtHTML. If you don't want the report to be the message body, what do you want? Can construct message in the procedure, so what do you want the message content to be?

Suggest not using PATH as variable or constant name, change to strPath, so as not to confuse with intrinsic property Path.

Step Debug. Read code - does each line make logical sense?

See if this stripped down version helps:
Code:
Private Sub send_Click()
Dim appOutLook As Outlook.Application, MailOutLook As Outlook.MailItem
Dim rsParent As DAO.Recordset2, rsChild As DAO.Recordset2
Dim fso As Object, SourceFolder As Object, SourceFile As Object
Const strPath As String = "P:\WISSEL\Expeditie\DataExpeditie"

'create the attachments folder
If Dir(strPath, vbDirectory) = "" Then
    MkDir strPath
End If

'extract files from table and save to folder
Set rsParent = Me.Recordset
rsParent.OpenRecordset
Set rsChild = rsParent.Fields("shipattachment").value
While Not rsChild.EOF
    rsChild.Fields("FileData").SaveToFile (strPath & "\" & rsChild.Fields("FileName"))
    rsChild.MoveNext
Wend
rsChild.Close
Set rsChild = Nothing

'open email and attach files
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
    .BodyFormat = olFormatRichText
    .To = "[EMAIL="bruce.zwarts@cevalogistics.com"]bruce.zwarts@cevalogistics.com[/EMAIL]"
    '.CC = " "
    .Subject = "Expedition - T1 Inbound"
    .HTMLBody = "Your text here." 'or restore code to export report to HTML and open and read file
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set SourceFolder = fso.GetFolder(strPath)
    For Each SourceFile In SourceFolder.Files
        .Attachments.Add SourceFile.PATH 'SourceFolder.Path contains the path+filename
    Next
    .Display 'display email after processing all attachments
    '.DeleteAfterSubmit = True 'this would let Outlook send email without saving to Sent bin
    '.Send
    'close fso objects
    Set SourceFile = Nothing
    Set SourceFolder = Nothing
    Set fso = Nothing
End With

Kill strPath & "\*.*" 'delete all files in the folder
RmDir strPath 'delete folder
End Sub
Is 'Expeditie' intential spelling? Is this really correct name of an existing folder?
 
Last edited:

Users who are viewing this thread

Top Bottom