By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,930 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,930 IT Pros & Developers. It's quick & easy.

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

P: n/a
=============================
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.