Emailing contents of folder (1 Viewer)

jfgambit

Kinetic Card Dealer
Local time
Today, 11:03
Joined
Jul 18, 2002
Messages
798
I was wondering if anyone had code examples for emailing the contents of an entire folder? The folder can have multiple file types in it (excel, pdf, word, etc) but every file need to be linked to the Outlook e-mail that Access produces.

I was trying to use this, but it completely ignores this part of the code:

Code:
Dim str_Source_Path As String
Dim str_File_Name As String

str_Source_Path = "C:\Temp"

Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.CreateItem(0)
Set SafeMail = CreateObject("Redemption.SafeMailItem")
Set SafeMail.Item = myItem

With SafeMail
    
    .Recipients.Add (Me.CSOA) ' Send To
    .Recipients.Add (strSendTo) ' test code
    
    .Subject = "A new Peer/Management Validation has been completed for SO #" & Me.SONbr & " by " & Me.Validator & " for " & Me.CSOA
    
    .Body = "Validation Request - SO #" & Me.SONbr & vbNewLine _
     & "Customer Name: " & Me.CustNm & vbNewLine _
     & vbNewLine _
     & vbNewLine _
     & "Order Validation Completed: " & Me.CreateDt & vbNewLine _
     & "Total Time Taken to Validate: " & strTimeDiff & vbNewLine _
     & "http://sp-fin/sites/OMApp/AuditValidation/Forms/AllItems.aspx" & vbNewLine _
     & vbNewLine
     
End With

    'Loop and attach all files from this folder
    '-------------------------------------------
    str_File_Name = Dir(str_Source_Path)
    Do While str_File_Name <> ""
    SafeMail.Attachments.Add (str_Source_Path & str_File_Name)
        str_File_Name = Dir
    Loop

With SafeMail
     .Importance = Outlook.olImportance.olImportanceHigh
     .Send
End With

Set Utils = CreateObject("Redemption.MAPIUtils")
Utils.DeliverNow
Set myOlApp = Nothing
Set SafeMail = Nothing
Set Utils = Nothing

Thanks for any help, been wracking my head searching every site I know of.
 

CyberLynx

Stuck On My Opinions
Local time
Today, 04:03
Joined
Jan 31, 2008
Messages
585
Perhaps you should try and just create a string with all the attachments (separated by semicolons) then add that string. I'm not sure if that will work though - It may be worth a try:

Code:
'Loop and attach all files from this folder
'-------------------------------------------
Dim AttachmentStrg As String

If Right$(str_Source_Path,1) <> "\" Then str_Source_Path = str_Source_Path & "\"
str_File_Name = Dir(str_Source_Path)

Do While str_File_Name <> ""
   AttachmentStrg = AttachmentStrg  & str_Source_Path & str_File_Name & ";"
   str_File_Name = Dir
Loop
AttachmentStrg = Left$(AtachmentStrg, Len(AttachmentStrg) - 1)
SafeMail.Attachments.Add AttachmentStrg

Mind you...I hope your not talking about attaching something like 100 files. :D

.
 
Last edited:

jfgambit

Kinetic Card Dealer
Local time
Today, 11:03
Joined
Jul 18, 2002
Messages
798
Let me give this a try and see, thanks.

And no, only 3 or 4. But you never know :)
 

jfgambit

Kinetic Card Dealer
Local time
Today, 11:03
Joined
Jul 18, 2002
Messages
798
Nope...got the message:

Runtime Error file "" does not exist.

We are close, but i can't seem to grasp what is missing.
 

CyberLynx

Stuck On My Opinions
Local time
Today, 04:03
Joined
Jan 31, 2008
Messages
585
My apologies. :eek:
The code I provided is flawed. There typos and things missing. This is what happens why supplying code on the fly. Try this:

Code:
[COLOR="DarkGreen"]'Loop and attach all files from this folder
'-------------------------------------------[/COLOR]
Dim AttachmentStrg As String

If Right$(str_Source_Path, 1) <> "\" Then str_Source_Path = str_Source_Path & "\"

[COLOR="DarkGreen"]'This will fill str_File_Name with the first file found in Folder.[/COLOR]
str_File_Name = Dir(str_Source_Path)

[COLOR="DarkGreen"]'Start creating the Attament String IF a file is found in folder. 
'If not then get outta here.[/COLOR]
If str_File_Name <> "" Then
   AttachmentStrg = AttachmentStrg & str_Source_Path & str_File_Name & ";"
Else
   Exit Sub
End If

[COLOR="DarkGreen"]'Loop through and get any other File Names...[/COLOR]
Do While str_File_Name <> ""
   str_File_Name = Dir
   If str_File_Name <> "" Then AttachmentStrg = AttachmentStrg & _
                               str_Source_Path & str_File_Name & ";"
Loop

[COLOR="DarkGreen"]'Remove the semicolon from the end of the Attachment String.[/COLOR]
AttachmentStrg = Left$(AttachmentStrg, Len(AttachmentStrg) - 1)

[COLOR="DarkGreen"]'Apply to mail attachment[/COLOR]
SafeMail.Attachments.Add AttachmentStrg

.
 

Users who are viewing this thread

Top Bottom