Concatenate Rich Text Fields (HTML) and display result on Access form

断了今生、忘了曾经 提交于 2019-12-12 17:46:45

问题


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


回答1:


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().

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




回答2:


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


来源:https://stackoverflow.com/questions/55771270/concatenate-rich-text-fields-html-and-display-result-on-access-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!