472,133 Members | 1,025 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

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

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
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
If RichText.SelLength = 0 Then
' if no text is select, disable the option on the dialog
.flags = .flags Or cdlPDNoSelection
' otherwise make "Selection" the default choice
.flags = .flags Or cdlPDSelection
End If
If Err = 0 Then
If .flags And cdlPDSelection Then
' User decided to print the current selection,
RichText.SelPrint .hdc
' User decided to print the entire contents, so select
saveSelStart = RichText.SelStart
saveSelLength = RichText.SelLength
RichText.SelStart = 0
RichText.SelLength = 999999
' Print on the device context returned by the common
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 1362

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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.