Go Back   Access World Forums > Microsoft Access Reference > Code Repository

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 03-15-2018, 03:44 AM   #1
Webbarr
Newly Registered User
 
Join Date: Mar 2018
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Webbarr is on a distinguished road
Add HTML tags to your rich text

I've made a basic function that adds some HTML tags to my rich text boxes based on what I want to display to the user, E.G. red / bold text for warnings etc...

Below is the main function & some examples of how I use it.

It's not very sophisticated but it's served me well so far & I wanted to share it. If anyone has any suggestions for improvements would love to hear back!

Code:
Option Explicit
Public Enum udtHTMLTags
    bwBold = 1
    bwItalic = 2
    bwUnderline = 4
    bwLineBreak = 8
End Enum
Public Function fnAddHTML(strInput As String, Optional HtmlTags As udtHTMLTags, Optional strColour = vbNullString) As String
    Dim strStart As String, strEnd As String

    If HtmlTags And bwBold Then
        strStart = "<b>"
        strEnd = "</b>"
    End If

    If HtmlTags And bwItalic Then
        strStart = strStart & "<i>"
        strEnd = strEnd & "</i>"
    End If

    If HtmlTags And bwUnderline Then
        strStart = strStart & "<u>"
        strEnd = strEnd & "</u>"
    End If

    If strColour <> vbNullString Then
        strStart = strStart & "<font color=" & Chr(34) & strColour & Chr(34) & ">"
        strEnd = strEnd & "</font>"
    End If

    If HtmlTags And bwLineBreak Then
        fnAddHTML = strStart & strInput & strEnd & "<br>"
    Else
        fnAddHTML = strStart & strInput & strEnd
    End If
End Function


Public Function fnRedText(strWarningMessage As String) As String
    fnRedText = fnAddHTML("Warning: ", , "FF0000") & strWarningMessage
End Function


Public Sub PrintText()
    Dim strPrintText As String

    strPrintText = fnAddHTML("Some bold text", bwBold)
    Debug.Print strPrintText

    strPrintText = fnAddHTML("Some bold & underlined", bwBold + bwUnderline)
    Debug.Print strPrintText

    strPrintText = fnAddHTML("All the options", bwBold + bwItalic + bwUnderline + bwLineBreak, "00FF00")
    Debug.Print strPrintText
End Sub

Webbarr is offline   Reply With Quote
Old 06-09-2018, 11:36 AM   #2
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 7,888
Thanks: 98
Thanked 1,963 Times in 1,827 Posts
isladogs is a glorious beacon of light isladogs is a glorious beacon of light isladogs is a glorious beacon of light isladogs is a glorious beacon of light isladogs is a glorious beacon of light
Re: Add HTML tags to your rich text

Thanks for this post which I've only just seen almost three months later.
You may be interested in an earlier post by cj_London on a similar theme
https://www.access-programmers.co.uk...d.php?t=290820
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 06-12-2018, 02:34 AM   #3
Webbarr
Newly Registered User
 
Join Date: Mar 2018
Posts: 3
Thanks: 2
Thanked 0 Times in 0 Posts
Webbarr is on a distinguished road
Re: Add HTML tags to your rich text

Thanks for posting that! I didn't receive a notification that I'd had a reply, maybe I need to have a look at my account settings.

It's an interesting read!

Webbarr is offline   Reply With Quote
Reply

Tags
function , vba

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML tags displayed in table teel73 Tables 1 01-19-2015 10:17 AM
HTML in Rich text field adds ">" Zakraket Modules & VBA 4 10-21-2014 10:45 AM
insert rich text (html format) from acces to word 2013 nikolaus.hofer Modules & VBA 1 07-24-2014 08:13 AM
Remove HTML and RTF Tags from String GohDiamond Queries 3 12-06-2013 03:00 PM
Question Use variable between HTML tags byTimber General 3 09-30-2012 09:47 AM




All times are GMT -8. The time now is 08:36 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World