I want to send several files attached to one e-mail message using MS Access 2007 (CDO.Message).
I have query where all files are listed and all file's pathes stored in a separate cell as Hyperlinks.
Here is below image which shows what I need:
[IMGnothumb]https://dl.dropbox.com/u/37289693/attach%20severa l%20files.jpg[/IMGnothumb]
and VBA code which I use:
Using this code I can compose textbody as I need, but can not attach ALL files from recordset. I have attached only first file (document1) but 3 times, depends on quantity of lines in my recordset, if 2 lines - 2 times, but always first file.
Any idea to solve it, please
I have query where all files are listed and all file's pathes stored in a separate cell as Hyperlinks.
Here is below image which shows what I need:
[IMGnothumb]https://dl.dropbox.com/u/37289693/attach%20severa l%20files.jpg[/IMGnothumb]
and VBA code which I use:
Code:
Private Sub btn4Pay_Click()
On Error GoTo btn4Pay_Click_Error
Dim rst As ADODB.Recordset
Dim strSQL As String
Dim sFilePath As String
Set rst = New ADODB.Recordset
strSQL = "[qryDocsToSend]" 'source of recordset
rst.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
sFilePath = Trim(rst(8)) ' file's path DocHyperLink
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "DOCUMENTS"
objMessage.From = """Sender"" <sender@gmail.com>"
objMessage.To = """Recepient"" <recepient@gmail.com>"
Do While Not rst.EOF
objMessage.TextBody = Trim(rst(0)) & " " & Trim(rst(1)) ' documents listed
objMessage.AddAttachment sFilePath' here I need several files to be attached, not only first from rst
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
objMessage.BodyPart.Charset = "windows-1251"
'===SMTP server configuration extracted ===
objMessage.Send
Any idea to solve it, please
Comment