Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outputing to File then emailing that file

Status
Not open for further replies.

WhtChoklat

Technical User
Jul 11, 2003
20
0
0
US
I am trying to ouput to a file then email an attachment of the file and a link to the webpage it will be on. I am receiving errors when I try to output the file, the email is working good. Here is my code, could someone please help?

Dim txtTO, txtCC, txtBCC, txtSubject, txtMessage As String
Dim outFile, filename, date1, path, ext As String

date1 = Date
path = pathname
ext = ".html"
filename = "Minutes" + date1
outFile = path + filename + ext

DoCmd.OutputTo acOutputReport, "Minutes - Report", acFormatHTML, outFile, False

txtTO = "riche@pjm.com"
txtCC = ""
txtBCC = ""
txtSubject = "Test18"
txtMessage = ""
DoCmd.SendObject acSendReport, "Minutes - Report", acFormatHTML, txtTO, txtCC, txtBCC, txtSubject, txtMessage, False
 
Is your output filename being put together correctly? Test this by putting:
Msgbox outfile
Before your OutputTo command.
You might be getting a type mismatch error on:
filename = "Minutes" + date1
so you may need to change it to:
filename = "Minutes" + CStr(date1)
And I see that you have no value for pathname...I assume you just omitted that part. If you are trying to get the application's pathname though, use app.path.

Hope that helps! If your filename is working fine, and it the the DoCmd part, let me know and we can work on that.
 
I was just omitting it for security reasons. This is the code I came up with in the end. Thank you for your help.

Dim txtTO, txtCC, txtBCC, txtSubject, txtMessage As String
Dim outFile, filename, date1, path, ext As String

MyDate = Date
date1 = Format(MyDate, "mmm d yyyy")
path = path
ext = ".html"
filename = "Minutes" + date1
outFile = path + filename + ext

DoCmd.OutputTo acOutputReport, "Minutes - Report", acFormatHTML, outFile, False

txtTO = "riche@pjm.com"
txtCC = ""
txtBCC = ""
txtSubject = "Test18"
txtMessage = ""
DoCmd.SendObject acSendReport, "Minutes - Report", acFormatHTML, txtTO, txtCC, txtBCC, txtSubject, txtMessage, False
 
I am trying to email a file that I am generating from a report. The file is being created successfully, but I am getting an error when I try to read the information or email it, I am not sure where the error is occuring. Here is my coding:

Dim txtTO, txtCC, txtBCC, txtSubject, txtMessage, message As String
Dim outFile, filename, date1, path, ext As String
Dim f, ts

MyDate = Date
date1 = Format(MyDate, "mmm d yyyy")
path = pathname
ext = ".rtf"
filename = "Minutes_" + date1
outFile = path + filename + ext
DoCmd.OutputTo acOutputReport, "Minutes - Report", acFormatRTF, outFile, False

Set f = outFile
Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
message = ts.ReadAll
ts.Close

txtTO = "riche@pjm.com"
txtCC = ""
txtBCC = ""
txtSubject = "Today's CMB Minutes"
txtMessage = message
DoCmd.SendObject acSendReport, "Minutes - Report", acFormatRTF, txtTO, txtCC, txtBCC, txtSubject, txtMessage, False

I hope someone can help me or at least point me in the right direction. Thanks in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top