Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Saving a .txt file as .rtf ...

Posted on 2006-06-20
23
Medium Priority
?
784 Views
Last Modified: 2012-06-27
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.
0
Comment
Question by:SpencerSteel
  • 7
  • 6
  • 5
  • +4
22 Comments
 
LVL 7

Expert Comment

by:Jonathan Kelly
ID: 16944157
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


0
 

Author Comment

by:SpencerSteel
ID: 16944179
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.

0
 
LVL 7

Expert Comment

by:wesbird
ID: 16944581
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 }

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 19

Expert Comment

by:Richard Daneke
ID: 16944729
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

0
 
LVL 19

Expert Comment

by:Richard Daneke
ID: 16944761
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
0
 
LVL 19

Expert Comment

by:Richard Daneke
ID: 16944777
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
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16946388
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
0
 

Author Comment

by:SpencerSteel
ID: 16949148
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.

0
 

Author Comment

by:SpencerSteel
ID: 16949523
*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.
0
 
LVL 19

Expert Comment

by:Richard Daneke
ID: 16950393
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
0
 

Author Comment

by:SpencerSteel
ID: 16951043
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.
0
 
LVL 19

Expert Comment

by:Richard Daneke
ID: 16953836
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
0
 
LVL 19

Expert Comment

by:Richard Daneke
ID: 16953859
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...
0
 
LVL 19

Expert Comment

by:Richard Daneke
ID: 16953937
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.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16954586
Have u tried linking your document to Access as a table?
File/Get External Data

then outputto that table to the various formats
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 17040033
DoDahD,

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

http://www.experts-exchange.com/Databases/MS_Access/Q_21606146.html#15151642

Hope this helps as well
0
 
LVL 65

Accepted Solution

by:
rockiroads earned 2000 total points
ID: 17304485
ok, never giving up (well try not to) on a challenge
Ive been looking at how we can do conversions in VBA and Word Automation just clicked to me.
This code does depend on Word being installed, but then if u got MSAccess, there is a very high chance that word is installed

What I do is open txt file in Word, then save as RTF format

Public Sub Txt2RTF()

    Dim objWord As Object
    Dim objDoc As Object
   
   
    Set objWord = CreateObject("Word.Application")
    Set objDoc = objWord.Documents.Open("c:\ee\dd.txt")
    objDoc.SaveAs "c:\ee\dd.rtf", 6
    objDoc.Close
    objWord.Quit
    Set objDoc = Nothing
    Set objWord = Nothing
   
End Sub



I have tested this on a couple of files and found it is producing a file with RTF tags
So this is my proposed solution.
I also use late binding so there is never a issue with references and different office versions!

0
 

Author Comment

by:SpencerSteel
ID: 17309198
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.
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17311654
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?
0
 
LVL 61

Expert Comment

by:mbizup
ID: 17311764
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


0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17311815
thanks
0
 

Author Comment

by:SpencerSteel
ID: 17419314
Sorted ! We got there ... thanks Rockiroads, worked very well !
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question