[AccessD] Rich text text boxes
John Colby
jwcolby at gmail.com
Tue Jul 12 10:00:35 CDT 2022
Yea but an editor is for human fingers and eyes, not VBA code.
On Tue, Jul 12, 2022 at 10:51 AM Gustav Brock via AccessD <
accessd at databaseadvisors.com> wrote:
> Hi John
>
> No slapping from me, as I've never found a use for these HTML-light
> textboxes.
> But who knows? I'll keep your code handy.
>
> FMS offers what seems to be a full-blown solution - at a cost:
>
>
> https://www.fmsinc.com/MicrosoftAccess/rich-text-format-memo/rich-text-editor.htm
>
> /gustav
>
> -----Oprindelig meddelelse-----
> Fra: AccessD <accessd-bounces+gustav=cactus.dk at databaseadvisors.com> På
> vegne af John Colby
> Sendt: 12. juli 2022 16:31
> Til: Access Developers discussion and problem solving <
> accessd at databaseadvisors.com>; John W Colby <jwcolby at gmail.com>
> Emne: [AccessD] Rich text text boxes
>
> 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
>
--
John W. Colby
Colby Consulting
More information about the AccessD
mailing list