[AccessD] Rich text text boxes

Ryan W wrwehler at gmail.com
Tue Jul 12 09:46:58 CDT 2022


I've recently been mucking with Rich Text too, though I am just allowing
users to use the text formatting options in the ribbon in the rich text
field.

I did find that the only thing setting the Text Format property on a
table/column does is make Access smarter when you drag and drop that
field/column onto a form (or when you use a form/report creation wizard),
it auto sets the control bound to the column to Rich Text .

Binding the form/report control to a non rich text column (say in a linked
table) only requires you to set the control to allow Rich Text to get those
"benefits" thankfully. I didn't want to mess with my ODBC Linking code to
also handle column properties.

And just like you, I did find that programmatically trying to add wording
to rich text fields stinks. I simply chose when I needed to add to that
column via VBA was to simply wrap whatever I was adding in div tags.   I'll
let my end users chose what to do with the phrasing added on their own
accord.

On Tue, Jul 12, 2022 at 9:31 AM John Colby <jwcolby at gmail.com> wrote:

> I'm sure some of our more experienced members will slap me around, but I
> just had to share my solution.
>
> Problem: the rich text text box in access "only works" bound to a rich text
> field.  Furthermore, the data in the field is HTML (ish) and all of that
> formatting stuff apparently is not available to get back from said field.
> Which makes writing rich text programmatically a roya PITA.  I have spent
> the morning googling and found pretty much nothing, at least in the Access
> vba side of the house.
>
> Solution:  Wrote my own.
>
> The answer lies in generating HTML dynamically.
>
> However before you can do ANYTHING you have to get a text box with it's
> format set to 'Rich Text' which is non-trivial.  In fact the only way I
> have found to do so is to create a table with rich text fields, then bind a
> form to that, then bind a text box to one of those fields, then set the
> format of the text box to 'Rich text' which is suddenly available simply
> because it is bound to a rich text field.  Once I had that , I unbound (is
> that a word) the text box, but it kept the 'Rich Text' format.  Voila a
> text box that can understand and process HTML tags.
>
> From there, I created a class (of course).  The objective of the class is
> to wrap a 'Rich text' text box and allow vba to do the mucking around with
> html format codes.
>
> I pass in the text box to the init and store the text box in the header of
> the class so I can access it inside of the class.
>
> I then wrote a function to pass in a message I wanted to display in the
> text box and a boolean to bold it or not, defaulted to not.
>
> Function fWriteTextBox(lstrMsg As String, _
>                             Optional blnBold As Boolean = False)
>
> Dim lstr As String
>     lstr = lstrMsg
>     If blnBold Then
>         lstr = "<b>" & lstr & "</b>"
>     Else
>     End If
>     If mLineCnt > 0 Then
>         lstr = "<br>" & lstr
>     End If
>     mstrHTMLMsg = mstrHTMLMsg & lstr
>     mtxtStatus.SetFocus
>   mtxtStatus.Text = mstrHTMLMsg
>     mLineCnt = mLineCnt + 1
>
> Exit_fWriteTextBox:
>     On Error GoTo 0
>     Exit Function
> end function
>
> In the form header
>
> Dim mclsLicenseStatusText As clsStatusText
>
> In the Form_Open
>
>     Set mclsLicenseStatusText = New clsStatusText  'Instantiate the beast
>     mclsLicenseStatusText.Init Me, txtLicenseStatus  'Pass in the text box
>
>     mclsLicenseStatusText.fWriteTextBox "This is a test" 'Write a string
> without bold
>     mclsLicenseStatusText.fWriteTextBox "This is a BOLD test", True ' Again
> with bold
>
> GUESS WHAT!  IT WORKS!!!
>
> The text box in my form displays the two lines of text stuff, one bolded,
> the other not.
>
> Can you say ROYAL PITA?  But IT WORKS.
>
> So now I need to flesh out the class to allow other format tags.  I desire
> to allow colors, bold, italics, font etc.  Slowly over time I think I can
> do this thing.  We shall see if and what the limitations of the text box
> are.  But I am simply jazzed that I can do anything at all of this nature.
>
> Furthermore the built up HTML string is available for me to look at / read
> back as opposed to the 'bound to a table' method.
>
> OK, now the real heavyweights of the list can commence the slapping.🤕😜😁
> --
> John W. Colby
> Colby Consulting
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>


More information about the AccessD mailing list