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

Importing .rtf as email template..no line breaks? 1

Status
Not open for further replies.

ChrisCalvert

Technical User
Mar 18, 2002
231
US
I am using the following bit of code graciously provided yesterday by scking (thanks again!) to import a .rtf file into a SendObject command. I want this to work as an email template.

---------------------------
Dim intFileNumber As Integer
Dim strTemplate As String

' Set up variable for the logfile
intFileNumber = FreeFile

Open LCase(strFilename) For Input As intFileNumber
Do While Not EOF(1) ' Loop until end of file.
Line Input #intFileNumber, TextLine
strTemplate = strTemplate & TextLine
DoEvents
Loop
Close intFileNumber
--------------------------------------

This code does work, but it does not preserve line breaks.
Is there anything I can alter to make the line breaks stay?
Or is there some other way to get mildly formatted text into this sendobject line:

DoCmd.SendObject acSendNoObject, , acFormatRTF, rst!Email, , , "Welcome to the test.", strTemplate, False


All help greatly appreciated,
Chris
 
Chris,

The code you have is for an ascii text file. I didn't realize you were using an RTF file. That changes the situation CONSIDERABLY. You now have to use a control or application to help you read the RTF file and place the text in a message. An RTF file is not text. It contains control codes which delimit actions such as BOLD, UNDERLINE, ENDOFPARAGRAPH which can not be read as text. Although I've used the RTF control in one application a few years ago, I can't say I could recommend you methodology. What I could ask is, if you are placing it as text in a message why would it need to be an RTF file?

Steve King Growth follows a healthy professional curiosity
 
It actually wouldn't, I can use plain text. I changed the file to .rtf just to see if that made a difference. The plain, simple, .txt is what I tried first, and it had no line breaks. Any way that I can get those in there is fine with me. Thanks once again for your assitance with this.
-Chris
 
I use a ReadTextFile class I found ages ago.
You can download it from my site:
Its very well documented and makes reading a line at a time from a text file an absolute breeze.
To use it create a new class module in your dB (you have to use the insert menu, it's different to a standard module) and paste the data in it and save it as TextFile
In your main module you can then dim tf as new TextFile and use the methods and properties to do what you want.

If you want a file that gives you an example, let me know & I'll knock one up for you.

Ben
----------------------------------
Ben O'Hara
bo104@westyorkshire.police.uk
----------------------------------
 
If you could show a little code that would read the above file into a variable much as the above code does, that would be very helpful. Defining new classes is a good deal above my head...
 
Trust me, it's dead easy. I'll knock something up for you when I get to work in the morning.
It might help if you send me an example of the text you are importing.

B ----------------------------------
Ben O'Hara
bo104@westyorkshire.police.uk
----------------------------------
 
The class was exported from a VB application and when trying to import into Access it will import it as a module. You will need to insert a new class and cut-paste the module code into the new class. A compile immediately afterwards show no syntax errors so it should be good to go.

Steve King Growth follows a healthy professional curiosity
 
Thanks all, things are shaping up now.
I used that class that you showed me, Ben. I had to add a carriage return manually, like this:
While Not myTextFile.EndOfFile
myTextFile.csGetALine
strTextLine = myTextFile.Text
strTemplate = (strTemplate + (Chr$(13))) + strTextLine
Wend

Then just use this to send it:
DoCmd.SendObject acSendNoObject, , acFormatRTF, rst!Email, , , "Email Subject",strTemplate, False

It sends emails now, and they have the same formatting as the template. Now I just need to do some error testing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top