开发者

Is there a limit to the size for a richtextbox in ms access?

开发者 https://www.devze.com 2022-12-29 22:43 出处:网络
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\"

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 开发者_StackOverflow社区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).


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?


See RichTextbox MaxLength too small. The limit is 2147483647 characters.


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


There seems to be a limit of 2048 characters to the setter of the Text property. An MS Access textbox also has a value property, which can be used to set the text in the textbox, and does not have that limit. Try something like the following, from the code within a form:

Me.myTextBox.value = textVariableContainingVeryLongString

Sorry if this is too late to be of value to you, but I ran into this problem recently, and the answer may be of value to someone reading this topic.


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.


I had the same problem. When this type of error occurs on text box use property .Value instead of .Text. In your case instead of:

frm(MyTxtBox).Text = frm(MyTxtBox).Text & message & Chr(13) & Chr(10)

use:

frm.Controls("MyTxtBox").Value=frm.Controls("MyTxtBox").Value & message & Chr(13) & Chr(10)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号