Guys,
I have been trying different things and not able to get my attachment to attach and save in my outlook. A blank email comes up with the users name in the To section but no attachment. How do I add and save my attachment report?
Here is what I have. I need some help - Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim MyFileName As String
-
Dim mypath As String
-
Dim temp As String
-
-
-
'mypath = "C:\Users\anoble\Documents\Test\"
-
-
Set db = CurrentDb()
-
-
Set rs = db.OpenRecordset("SELECT [email] FROM [tbl2018Extra]", dbOpenSnapshot)
-
-
Do While Not rs.EOF
-
-
temp = rs("EMAIL")
-
MyFileName = rs("EMAIL") & ".PDF"
-
-
Set myOutlook = New Outlook.Application
-
Set mymail = myOutlook.CreateItem(olMailItem)
-
-
DoCmd.OpenReport "rptPay", acViewReport, , "[email]='" & temp & "'"
-
'DoCmd.SendObject "rptPay", acSendObject, , temp
-
'DoCmd.OutputTo acOutputReport, "rptPay", acFormatPDF, "anoble@tec1943.com
-
DoCmd.OutputTo acOutputReport, "rptPay", "PDFFormat(*.pdf)", "rptPay", False
-
'mymail.To = temp
-
mymail.To = temp
-
'DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypath & MyFileName
-
'DoCmd.Close acReport, "rptPay"
-
mymail.Save
-
DoEvents
-
-
rs.MoveNext
-
Loop
-
-
-
rs.Close
-
Set rs = Nothing
-
Set db = Nothing
-
-
End Sub
I think the solution is - Mymail.Attacchments.Add [path and filename]
6 1602
I think the solution is - Mymail.Attacchments.Add [path and filename]
So, what I ended up doing was saving the report to a folder calling it "Report" then after running before the Loop deleting that file in the folder and going to the next record. Seemed to work
NeoPa 32,556
Expert Mod 16PB
Just for curiosity, the suggested solution that appears more straightforward was unacceptable because ...?
See post below - page refreshed automatically
Yeah, that's what I ended up doing. I was hoping I could add the attachment not having to export it to a folder but was not able. I used the:
Here is what I ended up doing. - Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim MyFileName As String
-
Dim mypath As String
-
Dim temp As String
-
-
-
mypath = "C:\Users\anoble\Documents\Test\"
-
-
Set db = CurrentDb()
-
-
Set rs = db.OpenRecordset("SELECT tbl2018Extra.EMAIL, tbl2018Extra.[Grand Total], tbl2018Extra.SALESMAN FROM tbl2018Extra WHERE (((tbl2018Extra.EMAIL) Is Not Null) AND ((tbl2018Extra.[Grand Total])>0));", dbOpenSnapshot)
-
-
Do While Not rs.EOF
-
-
temp = rs("EMAIL")
-
MyFileName = rs("EMAIL") & ".PDF"
-
SirName = rs("Salesman")
-
-
Set myOutlook = New Outlook.Application
-
Set mymail = myOutlook.CreateItem(olMailItem)
-
-
DoCmd.OpenReport "rptPay", acViewReport, , "[email]='" & temp & "'"
-
DoCmd.OutputTo acOutputReport, "rptPay", acFormatPDF, mypath & "Bonus" & ".pdf"
-
-
mymail.To = temp
-
End If
-
-
mymail.Attachments.Add "C:\Users\anoble\Documents\Test\Bonus.pdf"
-
mymail.Subject = "Bonus Report" & " - " & Format(DateAdd("m", -1, Date), "mmmm yyyy") & " - " & SirName
-
mymail.Body = "Attached are your Calculated Bonuses YTD" & " - " & Format(DateAdd("m", -1, Date), "mmmm yyyy") '& strBuffer
-
mymail.Save
-
Kill "C:\Users\anoble\Documents\Test\*.*"
-
DoEvents
-
-
rs.MoveNext
-
Loop
-
-
-
DoCmd.Close acReport, "rptPay"
-
MsgBox ("Done")
-
rs.Close
-
Set rs = Nothing
-
Set db = Nothing
-
-
End Sub
-
NeoPa 32,556
Expert Mod 16PB
Ah. That's much clearer then :-) I'll just set the post as Best Answer then. Cheers for the feedback.
Doh!! No I won't as it's already been done.
Note to self - book that eye test (then allow the doctor to run that alzheimers test I've been avoiding).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Anand |
last post by:
Hi i am having trouble adding a recordset into the access database,
the code seems to be working fine it passs and parses through all
variables just fine without showing any errors and also when i...
|
by: ed |
last post by:
i'm having trouble with a form. I want to be able to type in the address of
the form with the data for the form items in the URL (ie:
http://somesite.com/formpage.html?field1=data1&field2=data2)....
|
by: Lauren Wilson |
last post by:
I'm having trouble with the Access VBA help on my installation of A2K
with Dev tools. Every time I try to retrieve help for items listed in
the Object Browser (and SOME other items as well),...
|
by: Jozef |
last post by:
Hello,
I am trying to put together a module and open a workspace on a database that
has a simple password (using Access XP). This is the lin that I'm having
trouble with;
Set wrk =...
|
by: Jozef |
last post by:
Hello,
I'm having trouble with the download links on my web server. The error I'm
getting is;
CGI Timeout
The specified CGI application exceeded the allowed time for processing. The
server...
|
by: Jozef |
last post by:
Hello.
I'm having trouble creating a blank solution (and ASP.net web application)
from my laptop. I own the server (in fact it's sitting right next to me)
and have added the URL to the trusted...
|
by: Stu |
last post by:
Hi guys,
I've been having trouble getting the clock function to work portably,
please could I get some thoughts?
<Possibly OT comments>
It works fine on my laptop (under WinXP) and on my...
|
by: Fozzi |
last post by:
Hey all
I have been working on a project which allows me to write to a file and retrieve from that file, but i having trouble with it
These are my inputs:
private int flightno;
...
|
by: ERW2ERW |
last post by:
Could someone explain what I doing wrong?
I created a data base in access which contain all the employees who have cell phones.
the report gives me all the call made per employee , grouping...
|
by: BarbQb |
last post by:
Hi All,
I am having trouble filtering a report with a multiselect list box. The report is generated, but it is not filtered based on the selections of the list box:
lstVehID
Multi Select...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |