473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Having trouble attaching report and saving in Drafts folder

anoble1
245 128KB
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

Expand|Select|Wrap|Line Numbers
  1. Dim db As DAO.Database
  2.     Dim rs As DAO.Recordset
  3.     Dim MyFileName As String
  4.     Dim mypath As String
  5.     Dim temp As String
  6.  
  7.  
  8.     'mypath = "C:\Users\anoble\Documents\Test\"
  9.  
  10.     Set db = CurrentDb()
  11.  
  12.     Set rs = db.OpenRecordset("SELECT [email] FROM [tbl2018Extra]", dbOpenSnapshot)
  13.  
  14.     Do While Not rs.EOF
  15.  
  16.         temp = rs("EMAIL")
  17.         MyFileName = rs("EMAIL") & ".PDF"
  18.  
  19.         Set myOutlook = New Outlook.Application
  20.         Set mymail = myOutlook.CreateItem(olMailItem)
  21.  
  22.         DoCmd.OpenReport "rptPay", acViewReport, , "[email]='" & temp & "'"
  23.         'DoCmd.SendObject "rptPay", acSendObject, , temp
  24.         'DoCmd.OutputTo acOutputReport, "rptPay", acFormatPDF, "anoble@tec1943.com
  25.         DoCmd.OutputTo acOutputReport, "rptPay", "PDFFormat(*.pdf)", "rptPay", False
  26.         'mymail.To = temp
  27.         mymail.To = temp
  28.         'DoCmd.OutputTo acOutputReport, "", acFormatPDF, mypath & MyFileName
  29.         'DoCmd.Close acReport, "rptPay"
  30.         mymail.Save
  31.         DoEvents
  32.  
  33.         rs.MoveNext
  34.     Loop
  35.  
  36.  
  37.     rs.Close
  38.     Set rs = Nothing
  39.     Set db = Nothing
  40.  
  41. End Sub
May 10 '18 #1

✓ answered by twinnyfo

I think the solution is
Expand|Select|Wrap|Line Numbers
  1. Mymail.Attacchments.Add [path and filename]

6 1602
twinnyfo
3,653 Expert Mod 2GB
I think the solution is
Expand|Select|Wrap|Line Numbers
  1. Mymail.Attacchments.Add [path and filename]
May 11 '18 #2
anoble1
245 128KB
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
May 16 '18 #3
NeoPa
32,556 Expert Mod 16PB
Just for curiosity, the suggested solution that appears more straightforward was unacceptable because ...?
May 17 '18 #4
anoble1
245 128KB
See post below - page refreshed automatically
May 17 '18 #5
anoble1
245 128KB
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:
Expand|Select|Wrap|Line Numbers
  1. mymail.Attachments.Add
Here is what I ended up doing.
Expand|Select|Wrap|Line Numbers
  1. Dim db As DAO.Database
  2.     Dim rs As DAO.Recordset
  3.     Dim MyFileName As String
  4.     Dim mypath As String
  5.     Dim temp As String
  6.  
  7.  
  8.     mypath = "C:\Users\anoble\Documents\Test\"
  9.  
  10.     Set db = CurrentDb()
  11.  
  12.     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)
  13.  
  14.     Do While Not rs.EOF
  15.  
  16.         temp = rs("EMAIL")
  17.         MyFileName = rs("EMAIL") & ".PDF"
  18.         SirName = rs("Salesman")
  19.  
  20.         Set myOutlook = New Outlook.Application
  21.         Set mymail = myOutlook.CreateItem(olMailItem)
  22.  
  23.         DoCmd.OpenReport "rptPay", acViewReport, , "[email]='" & temp & "'"
  24.         DoCmd.OutputTo acOutputReport, "rptPay", acFormatPDF, mypath & "Bonus" & ".pdf"
  25.  
  26.         mymail.To = temp
  27.         End If
  28.  
  29.         mymail.Attachments.Add "C:\Users\anoble\Documents\Test\Bonus.pdf"
  30.         mymail.Subject = "Bonus Report" & " - " & Format(DateAdd("m", -1, Date), "mmmm yyyy") & " - " & SirName
  31.         mymail.Body = "Attached are your Calculated Bonuses YTD" & " - " & Format(DateAdd("m", -1, Date), "mmmm yyyy") '& strBuffer
  32.         mymail.Save
  33.         Kill "C:\Users\anoble\Documents\Test\*.*"
  34.         DoEvents
  35.  
  36.         rs.MoveNext
  37.     Loop
  38.  
  39.  
  40.         DoCmd.Close acReport, "rptPay"
  41.         MsgBox ("Done")
  42.     rs.Close
  43.     Set rs = Nothing
  44.     Set db = Nothing
  45.  
  46. End Sub
  47.  
May 17 '18 #6
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).
May 17 '18 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
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...
2
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)....
1
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),...
2
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 =...
0
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...
1
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...
2
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...
12
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; ...
3
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...
1
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...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.