tags:

views:

39

answers:

4

I'm using a richtext box to concatenate a log message.

And it seems I got an error: "the settings of this property is too long"

So is there a size limit ?

My code is very simple: I call multiple times:

 Public Function showMessage(MyTxtBox As String, ByVal message As String)

    Dim frm As Form
   On Error GoTo showMessage_Error

    Set frm = Forms.Item("FrmMessage")
    frm(MyTxtBox).Parent.SetFocus
    frm(MyTxtBox).Text = frm(MyTxtBox).Text & message & Chr(13) & Chr(10)

   On Error GoTo 0
   Exit Function

showMessage_Error:

    'MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure showMessage"
    frm(MyTxtBox).Text = ""
    Resume Next

End Function 

I use MS Access` TextBox selecting RichTextBox option;

As you can see I have partially solved the problem by using

frm(MyTxtBox).Text = ""
Resume Next

when an error occurs but that means I will lose all previous messages.

Isn't this incredible ?

Update: The form should not close by itself as It must be visible all the time as log message is appended to the form several times during a long processing task (importing several files in my case).

+1  A: 

See http://stackoverflow.com/questions/2739811/richtextbox-maxlength-too-small. The limit is 2147483647 characters.

Craig T
I'm far beyond a few dozens lines of 100 characters at most that's why I don't understand.Will investigate further.
+1  A: 

You may wish to read the full answer by Peter Duniho, here is an extract:

According to the documentation, the default defined maximum length (MaxLength property) for RichTextBox is Int32.MaxValue (about 2 billion), but you will run out of memory before you reach that limit (so the practical limit is actually how much virtual address space is available).

-- http://bytes.com/topic/c-sharp/answers/830657-result-richtextbox-appendtext-too-many-characters

Remou
+1  A: 

I assume you talking about access 2007, and the rich text box control. The others here have pointed you to c# rich text box, and I would not assume that the limitations are the same for ms-access. This control is native to ms-access. As for appending a new line, you could use:

For i = 1 To strLines
   strText = strText & "<br>"
   strText = strText & "<font face=Arial size=5 color=blue>" & _
               "This is comptuer generated " & i & " line of text" & _
               "</font>"
Next i

So, the br in the above is simply how new lines are added in rich text.

As for the limit? I am not sure why you hitting a limit here. Some functions in access are limited to 255 chars. However a rich text box on a form should have quite a bit of leeway. You might want to mention what context and how you using the rich text box. Are you talking about the native access 2007/2010 rich text box, or some ActiveX or 3d party add-in?

Albert D. Kallal
A: 

You've not explained what your code is supposed to do, nor what exact error is being thrown, nor by which line of code. But I'll just rewrite your code to fix the obvious errors:

  Public Function showMessage(ByVal strMyTxtBox As String, ByVal strMessage As String) As Boolean
    On Error GoTo showMessage_Error
    Dim frm As Form

    Set frm = Forms!FrmMessage
    DoCmd.SelectObject acForm, "FrmMessage", False 
    frm(strMyTxtBox) = frm(strMyTxtBox) & strMessage & vbCrLf
    showMessage = True

  exitRoutine:
    Set frm = Nothing
    Exit Function

  showMessage_Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in function showMessage"
    Resume exitRoutine
  End Function

There are a host of things I would do differently, but this cleans up the code you have so that it no longer has any errors in it (so far as I can tell).

EDIT:

If I were writing a subroutine to update a control on a form with messages, this is how I'd implement it:

  Public Sub AppendToControl(ByRef ctl As Control, ByVal varAppendValue, Optional ByVal bolScrollToEnd As Boolean = False)
    Dim varNewValue As Variant

    varNewValue = Mid(("12" + ctl) & (vbCrLf + varAppendValue), 3)
    ctl = varNewValue
    If bolScrollToEnd Then
       ctl.SelStart = Len(ctl.Text & vbNullString)
    End If
  End Sub

You could add an error handler, but I'm not sure what purpose it would serve, as it's pretty much impossible to pass valid parameters that would error out. Specifically, the original control can be Null and the passed message can be Null and it won't cause an error. It will also never have a trailing line feed, as the last message of your code would.

In any event, you'd call it with:

Call AppendToControl(MyForm!MyControl, "This is the message", True)

I wouldn't put the SelectObject code in the subroutine itself, as it doesn't seem appropriate to me. I'm not sure it's necessary or desirable, in any case.

David-W-Fenton
Hi, I don't understand why you don't understand what my code is supposed to do :)For example you created the exit routine whereas I don't want to close the form as It must be visible all the time as log message is appended to the form.
My code doesn't close the form. It only cleans up the form variable that pointed to it. There is really no purpose served in assigning the form to a form variable, and if I were writing it, I wouldn't do that, but I was just cleaning up your mess.
David-W-Fenton