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

Printing data of Rich Text Box

Status
Not open for further replies.

ZmrAbdulla

Technical User
Apr 22, 2003
4,364
AE
Hi,
I am using a Rich Texbox control on a form for an ole object field.
How can I print data of the data of the RTB?
I can print if I use controlSource as Memo field
instead of OLE object(keeping RTB on form) but it
changes the formating & inserts some more characters.
Data is not displayed if I use RTB on a report.
I need to keep the formatting and able to print through
the report.

Any idea?
thanks


Zameer Abdulla

 
I have a prototype that involves rich text, if you would like to take a look. It contains 4 tabs on a tabcontrol and each tab has a rich text field. Enter data in any of the rich text fields and click the save icon. Then with the cursor in one of the rich text fields, do a right click and what I have named as my "rtfZoomEditor" pops up with a number of edit buttons that are similar to MS WordPad. You should be able to edit and format your text. To place images, just drag them from their source and drop them in the rich text field. You can also cut and paste them. I would have left images in this sample, but the file size is to large to post in a forum. Let me know how it works for you. I'm still looking for a spell checker that works in rich text. Also I think the "Find" button should highlight all occurances of the word that it has found. I'm still looking for a way to accomplish that. There are still more rich text edit commands that are shown in the object browser for "RichTextLib" that would further enhance this project. If someone can help me with this I'd appreciate it. My prototype db is located at:
Here's a couple of links with some more samples I've found for those who are interested.





PC
 
Thanks PCGenie,
I have no problem on editing and formating the RTF. I am facing problem on printing using the RTF Control in report.
Memo Field can set to Shrink / Grow as per the size of the text in the control not RTF Control.
I have found an RTF control in Stephan Leban's Site. that is working better... You may also check it..

Let me go more on your application to tell about it...

Regards

Zameer Abdulla

 
My employer's IT Unit won't approve its use and I can't install it because IT Security blocks all unauthorized installations.
 
>ZmrAbdulla (TechnicalUser) said: "I have no problem on editing and formating the RTF."


I'm not likely to change to another richtext control soon, but could you share some of your information about richtext editing? I would like a "Find" function to highlight all occurances of the word that it has found. Also I'm looking for an RTF spellchecker. There are still more richtext edit commands that are shown in the object browser for "RichTextLib" that would further enhance this project. If you can help me with this I'd appreciate it. Thanks for your help.

~~ PC
 
Hi,
I will try my best to help you... I'm having a sample database that searches a word in memo field.. may be useful for you.... I will also search for a spell checker...

contact me if yo are interested the search database

zameerabdulla@hotmail.com

Regards

Zameer Abdulla

 
I found a rich text spellcheck module that uses MS Word's spellcheck. It goes in and out of Word and deposits the results back in the richtext field; however, the results are deposited in plain unformatted text. If you look at the code, could you tell me how I can get this to leave the resulting spellcheck text as the formatted richtext that originally went into the spellchecker?

Code:
========================================================
Option Compare Database

'Spell Check using Richtextbox to Word then back Method
Private Declare Function OpenClipboard Lib "User32" (ByVal hwnd As Long) As Long
Private Declare Function RegisterClipboardFormat Lib "User32" Alias _
"RegisterClipboardFormatA" (ByVal lpString As String) As Long
Private Declare Function EmptyClipboard Lib "User32" () As Long
Private Declare Function CloseClipboard Lib "User32" () As Long
Private Declare Function SetClipboardData Lib "User32" ( _
ByVal wformat As Long, ByVal hMem As Long) As Long
Private Declare Function GetClipboardData Lib "User32" (ByVal wformat As _
Long) As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wflags As Long, _
ByVal dwbytes As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
ByVal destination As Long, source As Any, ByVal length As Long)
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalFree Lib "kernel32" ( _
ByVal hMem As Long) As Long
Private Declare Function lstrcpy Lib "kernel32" (ByVal lstring1 As Any, _
ByVal lstring2 As Any) As Long

Private Const GHND = &O42
Private Const CF_TEXT = 1
'Private Const CF_RTFTEXT = &HFFFFBF01
Private Const MAXSIZE = 4096
Private Const GMEM_DDESHARE = &H2000
Private Const GMEM_MOVEABLE = &H2


'This code is on the command button.
'Spell Check using Richtextbox to Word then back Method
'To use this function, place "=SpellCheck()" in the
'onClick event for a command button on your form.

Public Function SpellCheck()

On Error GoTo SmartFormError

Dim sRTF As String
sRTF = Forms![fdlgRTFEditor]![RichText]
Dim Wrtf As String
Dim lSuccess As Long
Dim lRtf As Long
Dim hGlobal As Long
Dim lpString As Long
Dim lOrgTop As Long
lSuccess = OpenClipboard(Forms![fdlgRTFEditor]![RichText].hwnd)
lRtf = RegisterClipboardFormat("Rich Text Format")
lSuccess = EmptyClipboard
hGlobal = GlobalAlloc(GMEM_MOVEABLE Or GMEM_DDESHARE, Len(sRTF))
lpString = GlobalLock(hGlobal)
CopyMemory lpString, ByVal sRTF, Len(sRTF)
GlobalUnlock hGlobal
SetClipboardData lRtf, hGlobal
CloseClipboard
GlobalFree hGlobal
Dim oWord As Object
Dim oDoc As Object
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Add
oWord.Visible = True
lOrgTop = oWord.Top
oWord.WindowState = 0
oWord.Top = -3000
oWord.Selection.Paste
oDoc.Activate
oDoc.CheckSpelling

oWord.Selection.WholeStory
oWord.Selection.Copy

Dim hClipMemory As Long
Dim lpClipMemory As Long
Dim mystring As String
Dim Retval As Long

If OpenClipboard(0&) = 0 Then
MsgBox "cannot open Clipboard. Another app. may have it open"
GoTo OutofHere
End If
hClipMemory = GetClipboardData(CF_TEXT)
'hClipMemory = GetClipboardData(CF_RTFTEXT)
If IsNull(hClipMemory) Then
MsgBox "Could not allocate memory"
GoTo OutofHere
End If
lpClipMemory = GlobalLock(hClipMemory)

If Not IsNull(lpClipMemory) Then
mystring = Space$(MAXSIZE)
Retval = lstrcpy(mystring, lpClipMemory)
Retval = GlobalUnlock(hClipMemory)
mystring = Mid(mystring, 1, InStr(1, mystring, Chr$(0), 0) - 1)
Else
MsgBox "could not look to copy string from."
End If

OutofHere:
Retval = CloseClipboard()
Forms![fdlgRTFEditor]![RichText] = mystring
With oWord
.ActiveDocument.Close savechanges:=False
.Quit
End With

Exit_SmartFormError:
Exit Function

SmartFormError:

If Err = 2046 Or Err = 2501 Then
Resume Next
ElseIf Err = 440 Then
MsgBox "Error In Spell Check Function."
Resume Exit_SmartFormError
Else
MsgBox Err.Description
Resume Exit_SmartFormError
End If

End Function
========================================================

My prototype db is located at:
Thanks,
PC
 
I have shown below PART of what I use. This opens Word pastes the contents of the Richtext box in and then run spellchecker. When the spellchecker is done it SAVES the file in rtf format. Then the next line make the richtext box equal to that file and corrected text appears in the richtext box with the format intact.

ActiveXctl41 is the name of the richtext box.


Dim oWord As Object
Dim oDoc As Object
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Add
oWord.Visible = True
lOrgTop = oWord.Top
'oWord.WindowState = 0
'oWord.Top = -3000
oWord.Selection.Paste
oDoc.Activate
oDoc.CheckSpelling
oDoc.SaveAs Filename:="C:\My Documents\MySpellCheck.rtf", FileFormat:=wdFormatRTF
With oWord
.ActiveDocument.Close savechanges:=True
.Quit
End With
ActiveXctl41.Filename = "C:\my documents\mySpellCheck.rtf"
Me!ActiveXctl41.SetFocus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top