469,603 Members | 2,049 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,603 developers. It's quick & easy.

Solution: How to printout a richtextbox on an MS Access 2K form.

=============================
Problem:
=============================
How to printout a richtextbox on an MS Access 2K form.
=============================

=============================
Step by Step Solution:
=============================

1. Open a new form
2. Insert a Rich Text ActiveX and name it "RichText"
3. Insert a Common Dialog Box ActiveX and name it "CommonDialog1"
4. Save the new form and name it "TestForm"
5. Open the form code module for "TestForm" and insert the following
code.
===================================
Private Sub RichText_MouseDown(ByVal Button As Integer, ByVal Shift As
Integer, ByVal x As Long, ByVal Y As Long)
If Button = acRightButton Then
Call rtPrint
End If
End Sub

Public Function rtPrint()

'Use this code to print.

Dim saveSelStart As Long, saveSelLength As Long

On Error Resume Next
With CommonDialog1
.CancelError = True
.flags = cdlPDHidePrintToFile Or cdlPDNoPageNums Or
cdlPDReturnDC
If RichText.SelLength = 0 Then
' if no text is select, disable the option on the dialog
.flags = .flags Or cdlPDNoSelection
Else
' otherwise make "Selection" the default choice
.flags = .flags Or cdlPDSelection
End If
.ShowPrinter
If Err = 0 Then
If .flags And cdlPDSelection Then
' User decided to print the current selection,
RichText.SelPrint .hdc
Else
' User decided to print the entire contents, so select
it
saveSelStart = RichText.SelStart
saveSelLength = RichText.SelLength
RichText.SelStart = 0
RichText.SelLength = 999999
' Print on the device context returned by the common
dialog
RichText.SelPrint .hdc
' Restore old selection
RichText.SelStart = saveSelStart
RichText.SelLength = saveSelLength
End If
End If
End With
End Function
===================================
6. Close the form code module for "TestForm"
7. Close Design View and the open "TestForm"
8. Enter text into the Rich Text field on the form.
9. Right click to open print dialog
10. Click on OK to print.
11. Voila
Nov 12 '05 #1
0 1273

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by John Broderick | last post: by
2 posts views Thread by Smartin | last post: by
2 posts views Thread by KenH | last post: by
1 post views Thread by Nathan Carroll | last post: by
9 posts views Thread by James Wong | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.