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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use a txt file as the body txt of an emai;

Status
Not open for further replies.

albyh

Technical User
May 10, 2003
32
GB
I trying to set up a function that automatically sends an email using a certain text file as the body text. Its either this or if there is any way to insert line breaks.
This is the code I am currently using.

Function SendOrderEmail()
MessageTxt = "Txt here"
DoCmd.SendObject acSendNoObject, Email, acFormatTXT, "email@email.com", "", "", "Re Order", MessageTxt, False
End Function
 

Albyh -

Hope I understand what you are asking. Sometimes free advice isn't worth the price. ;)
The code below took your original function and I copied a bit of code from MS Access help. The code reads a textfile in and stores it to your mesagetxt variable.

There is also a commented line that shows how to add carriage return line feed.


Function SendOrderEmail()
Dim messagetxt As String
Dim fs, f, ts, s

Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile("C:\testfile.txt")
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
's = ts.ReadLine
messagetxt = ts.readall
ts.Close

' original text message with carriage return line feed
'messagetxt = "Txt " & vbCrLf & vbCrLf & "here "

DoCmd.SendObject acSendNoObject, Email, acFormatTXT, "mike_tompkins@comcast.net", "", "", "Re Order", messagetxt, False

End Sub
 
This has worked great. Thanks a lot
Alban
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top