Good day,
I want to send an attachment individually for each record on my form, in order to simplify things, I do create a pdf file in a directory within that code, everything is working perfectly and emails are sent to each individual recipients with that code.
In the query, I have 2 fields txtDir and fileName, the txtDir specify the directory you can find the file and the fileName's field specify exactly the name of the file to be attach...
so in my code you will notice these 3 lines:
strDir = rst![txtDir]
strFile = rst![fileName]
strfileName = Dir(strDir & strFile)
When I look at each one of them in the code by using debug I can see that these 3 lines returns the right data:
strDir = C:\Auto-Caisse\Clients\Courriel client\Rapports États de compte PDF\
strfile =- CLAUDE LAROCQUE_CVM101.pdf
strfileName =C:\Auto-Caisse\Clients\Courriel client\Rapports États de compte PDF\CLAUDE LAROCQUE_CVM101.pdf
Of course all records has their own strfile name..
I want to be able to send each recipients their own filename:
Here is my code so far:
thanks for your help
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 Private Sub Commande295_Click() Dim dbs As DAO.Database Dim rst As DAO.Recordset Dim objOutlook As New Outlook.Application Dim objMail As Outlook.MailItem Dim strDir As String Dim strFile As String Dim strfileName As String Set dbs = CurrentDb Set rst = dbs.OpenRecordset("tblMessages Requête") Set dbs = CurrentDb DoCmd.SetWarnings False DoCmd.Hourglass True Set objMail = objOutlook.CreateItem(olMailItem) strDir = rst![txtDir] strFile = rst![fileName] strfileName = Dir(strDir & strFile) With objMail While Not rst.EOF With rst fileName = Application.CurrentProject.Path & "\Rapports États de compte PDF\" & rst![Classer sous] & "_" & rst![NoCarteRepas] & ".pdf" DoCmd.OutputTo acReport, "rptMessagesUnique", acFormatPDF, fileName, False End With rst.MoveNext Wend Set rst = dbs.OpenRecordset("tblMessages Requête") While Not rst.EOF With .Recipients.Add(rst![Courriel]) .Type = olTo End With rst.MoveNext Wend .Send End With DoCmd.Hourglass False End Sub
Claude from Quebec, Canada
Partager