none
Rich Text formatting with VBA and Regex in Access 2013

    Question

  • I need a way to programmatically modify RTF formatting in Access 2013.  The Mini Toolbar is a major limitation since there is no way to control it, and there is no other way to programmatically change formatting.

    Since Microsoft RTF is essentially Markup language, Regex should be able to do this.  Perhaps something like this:

    Function ChangeFontFace()
    '[Microsoft VBScript Regular Expressions 5.5]
    'C:\Windows\system32\vbscript.dll
      Dim rgx As RegExp
      Set rgx = New RegExp
      rgx.Pattern = "<font face="
      If rgx.Test(strMyRTF) Then
        rgx.Replace(oldFont, newFont)
      End if
    End Function
    Before I reinvent the wheel, can someone point me to code samples with VBScript Regex to modify RTF formatting?  Since MS RTF is a published spec, I'd think there would be something out there.

    Monday, February 18, 2013 5:35 PM

Answers

All replies

  • What MS calls Rich Text in Access is NOT Rich Text as defined by MS's Rich Text Format (RTF) Specification.  If it can be called anything, it should referred to as "Access RTF", which is merely a small subset of HTML tags.

    According to this document:

    http://office.microsoft.com/en-us/access-help/insert-or-add-a-rich-text-field-HA010014097.aspx

    There are 16 formatting options used in Access RTF:

    Font name
    Font size
    Bold
    Italic
    Underline
    Align left
    Center
    Align right
    Numbering
    Bullets
    Font color
    Text highlight color
    Decrease indent
    Increase indent
    Left-to-right
    Right-to-left

    These are all represented with standard HTML tags.  As for how to create, add, change and delete Access RTF formatting, the question is whether to use Regex, an HTML parser, or this thingy called Microsoft HTML Object Library [MSHTML.TLB].

    I think what I really want is a full-featured HTML Editor that stores content in Access.  I found this:

    http://nbit.net.au/vpages.aspx?ID=HTML%20Editor%20OCX

    But might be better off writing my own using MSHTML.

    • Edited by john1519 Tuesday, February 19, 2013 2:34 AM
    Tuesday, February 19, 2013 12:22 AM
  • Hi john,

    You may have a look at the following link. It provides a HTML Editor built around the Web browser control.

    HTML Editor 

    http://lebans.com/htmleditor.htm

    You may also check this link:

    MS Access: HTML Editor control to use in forms

    http://blog.vishalon.net/index.php/ms-access-html-editor-control-to-use-in-forms/

    Have a nice day.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Tuesday, February 19, 2013 8:08 AM
  • Thanks for the links.  There's a demo database available on each site: A2KSHTMLver17.mdb at lebens.com and AccessHTMLEditor.mdb at vishalon.net.  AccessHTMLEditor.mdb uses an external file (ckeditor.html) with JavaScript (not that I have anything against JavaScript).  Both have references to Microsoft Internet Controls (C:\Windows\System32\ieframe.dll); neither uses Microsoft HTML Object Library (C:\Windows\System32\mshtml.tlb).

    Using the Rich Text feature in Access (which is not Rich Text at all, but rather HTML) is like having built-in HTML editor for records bound to an RTF field.  But it's far too limited: zero programmatic control and the cumbersome Mini Toolbar as the only way to apply formatting.

    What I'm looking for is something in the middle, between "Access RTF" and a full-blown HTML editor--something with which I can edit and store HTML content in an Access database... basically, a CMS for HTML documents/HTML email templates.

    I'll see what I can do with MSHTML and have a look at those demos as I get started.  Further suggestions welcome.

    Regards,

    John







    • Edited by john1519 Tuesday, February 19, 2013 7:44 PM
    Tuesday, February 19, 2013 1:56 PM
  • Hi John,

    Please check these links to see if they help:

    Microsoft Beefs Up VBScript with Regular Expressions

    Formatting HTML code snippets with Ten Ton Wrecking Balls

    Thanks.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, February 20, 2013 2:14 AM
  • Hi John,

    I temporarily marked the reply as answer and you can unmark it if it provides no help.

    Thanks for your understanding and have a nice day.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 28, 2013 9:44 AM