Concatenate Rich Text Fields (HTML) and display re

2019-07-20 16:10发布

I have an access database which deals with "articles" and "items" which are all textual stuff. An article is composed of several items. Each item has a rich text field and I wish to display the textual content of an article by concatenating all rich text fields of its items.

I have written a VBA program which concatenates the items rich text fields and feeds this into an independent TextBox control on my form (Textbox.Text = resulting string) but it does not work, I get an error message saying "this property parameter is too long". If I try to feed a single textual field into the Textbox control, I get another error stating "Impossible to update the recordset" which I do not understand, what recordset is this about ?

Each item field is typically something like this (I use square brackets instead of "<" and ">" because otherwise the display of the post is not right) [div][font ...]Content[/font] [/div]", with "[em]" tags also included.

In front of my problem, I have a number of questions :

1) How do you feed an HTML string into an independent Textbox control ?

2) Is it OK to concatenate these HTML strings or should I modify tags, for example have only one "[div]" block instead of several in a row (suppress intermediate div tags) ?

3) What control should I use to display the result ?

You might well answer that I might as well use a subform displaying the different items of which an article is made up. Yes, but it is impossible to have a variable height for each item, and the reading of the whole article is very cumbersome

Thank you for any advice you may provide

2条回答
看我几分像从前
2楼-- · 2019-07-20 16:37

It works for me with a simple function:

Public Function ConcatHtml()

    Dim RS As Recordset
    Dim S As String

    Set RS = CurrentDb.OpenRecordset("tRichtext")
    Do While Not RS.EOF
        ' Visually separate the records, it works with and without this line
        If S <> "" Then S = S & "<br>"

        S = S & RS!rText & vbCrLf
        RS.MoveNext
    Loop
    RS.Close

    ConcatHtml = S

End Function

and an unbound textbox with control source =ConcatHtml().

Screenshot

In your case you'd have to add the article foreign key as parameter to limit the item records you concatenate.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-07-20 16:45

The "rich text" feature of a textbox is only intended for simple text.

We use the web browser control to display a larger amount of HTML text, and load it like this:

Private Sub Form_Current()

    LoadWebPreview

End Sub


Private Sub HtmlKode_AfterUpdate()

    LoadWebPreview

End Sub


Private Sub LoadWebPreview()

    ' Let the browser control finish the rendering of its standard content.
    While Me!WebPreview.ReadyState <> acComplete
        DoEvents
    Wend

    ' Avoid the pop-up warning about running scripts.
    Me!WebPreview.Silent = True

    ' Show body as it would be displayed in Outlook.
    Me!WebPreview.Document.body.innerHTML = Me!HtmlBody.Value

End Sub
查看更多
登录 后发表回答