Results 1 to 1 of 1
  1. #1
    Join Date
    Feb 2007
    Posts
    4

    Unanswered: Lebans RTF2.ocx Read-Only Printing Problem

    You may receive a Read-Only error when attempting to print a report containing this control. This usually happens when you are trying to assign a string to the rtfText property in one of the Format events. The error does not occur when the report preview is being created but it does occur during printing from the preview window. For some reason, if you first preview the report and then print from the preview window, the rtfText value becomes Read Only.

    Unfortunately, the Format events are fired both during creation of the preview and when printing the report from the preview window. You can avoid the error by making sure you DO NOT assign anything to the property during printing, if you have already done so in the preview. The problem is how to determine whether the Format event is firing when the preview is being created or when the preview is being printed.

    I used the following hack:

    Before assigning data to the control, it's PlainText property has a value of, "RTF2 Control Design View Window". This value gets overwritten when you assign a value to rtfText. I simply check the PlainText value and, if it is "RTF2 Control Design View Window", I know I have not yet assigned a value to rtfText. If PlainText is equal to anything else, I know I have already assigned a value to rtfText and I don't assign the value again.

    Here is an abridged example of my ReportHeader_Format event:

    ' Set the Rich TextBox's contents
    Private Sub ReportHeader_Format(Cancel As Integer, FormatCount As Integer)
    On Error GoTo ErrorHandler
    Dim rs As Object
    Dim strSQL As String
    Dim lngJobID As Long
    Dim strHeaderFileName As String
    Dim fh As Integer

    If rtfHeader.Object.PlainText = "RTF2 Control Design View Window" Then
    strSQL = "SELECT lngJobID FROM SystemDefaults"
    Set rs = CurrentDb.OpenRecordset(strSQL)
    lngJobID = rs("lngJobID")

    strSQL = "SELECT strHeaderFileName FROM Job WHERE lngJobID = " & lngJobID
    Set rs = CurrentDb.OpenRecordset(strSQL)
    strHeaderFileName = rs("strHeaderFileName") & ""
    rs.Close

    If Len(Trim(strHeaderFileName)) > 0 Then
    If Len(Dir(strHeaderFileName)) > 0 Then
    'open the rich text file
    fh = FreeFile(0)
    Open strHeaderFileName For Input As fh
    rtfHeader.Object.rtfText = StrConv(InputB$(LOF(fh), fh), vbUnicode)
    Close fh
    Else
    MsgBox "Header file not found.", vbOKOnly Or vbExclamation, "Observation Reports"
    End If
    End If
    End If

    ExitProcedure:
    Set rs = Nothing
    Exit Sub

    ErrorHandler:
    MsgBox Err.Description
    Resume ExitProcedure

    End Sub

    GeoNet Technologies, Inc.
    Last edited by GeoNet; 02-27-07 at 22:39.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •