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!

How canI view a RTF in a form

Status
Not open for further replies.

lashwarj

IS-IT--Management
Joined
Nov 1, 2000
Messages
1,067
Location
US
Is there a viewer that will allow me to view RTF files in a viewer on a form
 
Sure the Rich Text Control. There's an example in ...\Samples\Solution\OLE\Rtf.scx.

DO Form _samples+"\Solution\OLE\Rtf.scx"

This assumes you've properly installed the sample code from the MSDN Library CD.

Rick
 
ok it brings me to the same deal I already had, I have my path of the RTF i want to view saved in a memo field but everytime instead of showing the contents of the RTF it displays the path, how do i correct this
 
lashwarj

Add a new form property, .cRTF, or similar.

In the .Init() event of the form, put

THISFORM.cRTF = MYTABLE.rtf_memo

Set the .ControlSource of THISFORM.oleRTF to be THISFORM.cRTF. HTH

Chris [pc2]
 
lashwarj

"I have my path of the RTF i want to view saved in a memo field"

The last post requires that the actual RTF file is stored in the memo field, not the path\filename, so you would need to use APPE MEMO MYTABLE.rtf_memo FROM path\filename.rtf etc get the files into the table.

IIRC, you cannot directly set the .ControlSource of the oleRTF control directly to MYTABLE.rtf_memo hence the workaround through the form property. HTH

Chris [pc2]
 
what do i do with that I am lost ?
 
lashwarj

What you need on your form is the RichTextCtrl, which I refer to as THISFORM.oleRTF, to view the RTF file.

For a reason that I can't remember, you need to set the .ControlSource of the control THISFORM.oleRTF to the form property, THISFORM.cRTF, and the form property in turn is set to a memo field containing the RTF file, not simply the path\filename of the RTF file.

Setting THISFORM.cRTF = MYTABLE.fieldname, (field containing the path\filename), may well work, (you need to try it), but if the RTF file is contained in the memo field, it will work. HTH

Chris [pc2]
 
ok i am lost kind of. I have a path saved in a memo field
ex. C:\doc\test.rtf and the path may not be the same for everyone. At present the rtf control only shows the path, it does not show the contents of the file. How do i get it to do this and what is the easiest way. The program has no data in it except the test data I am entering so would it be easier to set a default directory then only use filenames
 
lashwarj

"You need to set the .ControlSource of the control THISFORM.oleRTF to the form property, THISFORM.cRTF, and the form property in turn is set to a memo field containing the RTF file."

THISFORM.oleRTF.ControlSource = THISFORM.cRTF

and

THISFORM.cRTF = MYTABLE.rtf_memo

Try that and advise how you get on. HTH

Chris [pc2]
 
I am getting a type missmatch. I have the =THISFORM.cRTF in my controlsource for the olecontrol (RTF Viewer) and then in the forms init i have the THISFORM.cRTF = open_issues.attached_file
 
lashwarj

You need to APPE MEMO MYTABLE.rtf_memo FROM path\filename.rtf

Then in your .Init() event put:-

THISFORM.cRTF = MYTABLE.rtf_memo
THISFORM.oleRTF.Refresh()

I've just tried it and it works fine. HTH

Chris [pc2]
 
ok how or where do i put the APPE MEMO MYTABLE.rtf_memo FROM path\filename.rtf
 
lashwarj

Modify your table structure and add a new memo field rtf_memo.

SELE MYTABLE
APPE BLAN
APPE MEMO MYTABLE.rtf_memo FROM path\filename.rtf

and then use the code in the previous post. HTH

Chris [pc2]
 
ok so why am I taking from one memo field and placing in another, then the FROM path\Filename.rtf is stored in the memo field, how do I refrence it. This is confusing me, all I seemt o still get is the location showing in the viewer not the actual document. then I do not understand why I am taking from one memo field and placing in another.
 
lashwarj

What you would like to do is to use a path\filename as the .ControlSource for the RTF control in the same way that you can set the picture property to a path\filename and display the relevant image.

If you examine the sample in Solutions, you will see the .ControlSource is a memo field in a table called RTF.

The memo field does not contain the path\filename as you, lashwarj, would like but instead contains the RTF file itself.

Some time back, (can't remember when), it used to be necessary to indirectly set the .ControlSource of the ole control through a form property - it now seems on testing today, that is no longer the case.

What does remain is the fact that the RTF file needs to be in a memo field in a cursor/table for the ole control to be able to display/edit the file.

If you still want to use the path/filename as the .ControlSource for the ole control, you would need to create a cursor and then with a single record in the cursor:-

APPE MEMO MYCURSOR.rtf_memo FROM MYTABLE.filename OVERWRITE
THISFORM.oleRTF.Refresh()

To simplify matters further, you do not need a memo field for your path\filename - use C(254) instead. HTH

Chris [pc2]
 
my RTF is saving the path, the memo field displays C:\test\test.rtf
 
lashwarj

The memo field must contain the RTF file itself, NOT the path\filename! HTH

Chris [pc2]
 
what do you recommend using then if i want to view a document with only savng the path
 
lashwarj

"If you still want to use the path/filename as the .ControlSource for the ole control, you would need to create a cursor and then with a single record in the cursor:-"

APPE MEMO MYCURSOR.rtf_memo FROM MYTABLE.filename OVERWRITE
THISFORM.oleRTF.Refresh()
HTH

Chris [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top