Link to home
Start Free TrialLog in
Avatar of SpencerSteel
SpencerSteel

asked on

Saving a .txt file as .rtf ...

Guys,

For reasons I won't bore you with, my little Access VBA app needs to create 3 versions of a compiled 'string' based file ...

1. a .txt version
2. a HTML version
3. a .rtf version

No problems with 1 & 2 ... but the .rtf version is causing me a problem.

I'm compiling my string-based document and saving it using FSO ... cheekily just changing the extension ... but the .rft 'knows' it is not true .rft ... that is having a knock-on effect for what I am actually using this for (pre-designing Autosigs. in Outlook, if you are interested)

Anyone know how I can save a .txt file as 'real' .rft ??

Thanks,

S.S.
Avatar of Jonathan Kelly
Jonathan Kelly
Flag of Ireland image

if you save the file as rtf rather than changing a txt extension - does that make a difference ?

maybe >> use ole to load it into word and save it as rtf


Avatar of SpencerSteel
SpencerSteel

ASKER

mmm ... thought this might be the solution ... anyone want to write the code for me for the 500 points, where "myString" is the body copy (sorry - really rushed here)

Cheers,

S.S.

Simple

Put the "Microsoft Rich Textbox Control 6 (SP6)" or whatever version you have on a hidden form.  Call it RTFEdit

Simply call it to convert txt to rtf like this:

RTFEdit.Text = txtPlainText
txtRTF = RTFEdit.TextRTF

e.g. input:

Use the Microsoft Rich Textbox Control

output:

{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\lang1033\f0\fs17 Use the Microsoft Rich Textbox Control
\par }

DoCmd.OutputTo ObjectType, ObjectName, OutputFormat, OutputFile, AutoStart

Where ObjectType can be acOutputFunction or acOutputStoredProcedure and
where AcFormat can be one of these acFormatASP, acFormatHTML, acFormatRTF, or acFormatTXT

Your code to a function that constructs a string would be:

1. DoCmd.OutputTo acOutputFunction, "MyString", AcFormatTXT, ".\MyString", False
2. DoCmd.OutputTo acOutputFunction, "MyString", AcFormatHTML, ".\MyString", False   or
    DoCmd.OutputTo acOutputFunction, "MyString", AcFormatASP, ".\MyString", False
3. DoCmd.OutputTo acOutputFunction, "MyString", AcFormatRTF, ".\MyString", False
Oops, Function name needed not string variable....

1. DoCmd.OutputTo acOutputFunction, "funMyString", AcFormatTXT, ".\MyString", False
2. DoCmd.OutputTo acOutputFunction, "funMyString", AcFormatHTML, ".\MyString", False   or
    DoCmd.OutputTo acOutputFunction, "funMyString", AcFormatASP, ".\MyString", False
3. DoCmd.OutputTo acOutputFunction, "funMyString", AcFormatRTF, ".\MyString", False
I was going to suggest you save your txt in a table, then output that using DoCmd.OutputTo

Now DoDahD has already given you the various options and so you don't have to worry about creating specific types
Thanks DoDahD - I like the idea but I'm a bit stuck

I've assigned this code to a blank form button ...

   DoCmd.OutputTo acOutputFunction, fnCreateString, acFormatRTF, ".\MyString", False

where fnCreateString (for test purposes is)

   Public Function fnCreateString()

   fnCreateString = "blah blah blah!"

   End Function

But on clicking the button, Access is saying that it "can't find the object 'blah blah blah'" ...

I've obviously missed the point on this. I thought the idea was to 'OutputTo' the result of the function ... whereas Access is just trying to output the entire function ... how does that work?

Thanks,

S.S.

*sigh* ... been playing around with outputting queries (looks ugly, can't get rid of field name) and reports (does that whole 'exporting to...' flashing box thing (not good enough)

I've very frustrating. Would like to know if the Function,Module thing might help.

Thanks,

S.S.
You are on the right track.

   Public Function fnCreateString()

   fnCreateString = "blah blah blah!"

   End Function
Redefines fnCreateString as "blah blah blah!"   The function needs to return a string.

   Public Function fnCreateString(strCreateString as String)

   Dim strCreateString as String
   strCreateString = "blah blah blah!"

   End Function

- D
Argh ! I must be really thick ... i'm still getting an error on the call ... what is wrong with this ?

---------

DoCmd.OutputTo acOutputFunction, fnCreateString(), acFormatRTF, "c:\test.rtf", False

----------

 Public Function fnCreateString()

  Dim strCreateString As String
   
   strCreateString = "blah blah blah!"

   End Function

--------

Thanks so much,

S.S.
S.S.
I, too, have had trouble using the acOutputFunction option.  I cannot find a good reference on its use.

Your string data is stored in a table? , query?, or what?

I have had good luck in testing with acOutputQuery and acOutputReport.  Is your string available in a different object?

- DD
BTW,
I created a table, a query, and a report.
The query and table add column headings, the report can be created w/out headers or footers and will format for appearance (fonts, sizes, positions).  
Let me know your progress...
S.S.
If you want to look at the database I was using follow this link:

Direct link to your file
https://filedb.experts-exchange.com/incoming/ee-stuff/240-EE-Test.zip 

The function trash was my attempt to follow my own advice  :-(

Leaving the filename option blank in OutputTo prompts for a filename.
Have u tried linking your document to Access as a table?
File/Get External Data

then outputto that table to the various formats
DoDahD,

Check this link, it has interesting info on what make a file an .rtf File.

https://www.experts-exchange.com/questions/21606146/Converting-Access-Memo-field-to-Sql-as-a-RTF-field.html#15151642

Hope this helps as well
ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello Rockiroads,

You really don't give up, do you !

Sadly, I'm right slap-bang in the middle of an absolute nightmare of a (non-development) issue at the moment and am going to struggle to test this out right now, but I trust you!

I'm going to add it to my To Do list and make sure I check it out asap and award you your hard-earned points !

Just so you know I haven't disppeared into an EE blackhole

Thanks for caring :)

S.S.
S.S.
No worries. Twas a good challenging question, one hopefully I have sorted for you.
Any problems let me know. I dont plan on going anywhere quite just yet, well perhaps next week, if and when I win the lottery :)

Miriam, is it okay to leave this question open a bit longer?
No problem...

S.S.,  Just please follow up on this within the next 21 days so that we know that you are still interested in the question.

Thanks,

mbizup
EE Cleanup Volunteer


thanks
Sorted ! We got there ... thanks Rockiroads, worked very well !