Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    mredmond13 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    Louisiana, USA
    Posts
    16

    Using VBA to Change a String's FORE and BACKGROUND Colors

    I have an unbound text box into which I use VBA to load a string. I am reading through a small table to get "tag" words associated with a transaction and I build a string. The code for this is below:


    Code:
        
        Do While Not rs.EOF
            If Len(CaseTags) > 0 Then
                CaseTags = CaseTags & ",  " & "<font color=red>" & rs!TagTitleMinor & "</font>"
            Else
                CaseTags = "  " & "<font color=red>" & rs!TagTitleMinor & "</font>"
            End If
            rs.MoveNext
        Loop
    I change the ControlSource of the text box and it shows up as follows:

    Click image for larger version. 

Name:	Textbox 1.PNG 
Views:	26 
Size:	3.8 KB 
ID:	34940

    Is there any way to change the font background color - not the background of the entire text box, just the string text? For example, black text on a gray background in a white text box.
    Thanks in advance.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Have to say no. I don't think even RichTextFormat could accomplish that.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    If I've understood correctly I have to disagree. You can achieve something like this

    Click image for larger version. 

Name:	Capture.JPG 
Views:	27 
Size:	10.9 KB 
ID:	34941

    See this link

    https://www.access-programmers.co.uk...ight=rich+text

    for a small app so you can see the codes required

    but in principle you need

    <font style="BACKGROUND-COLOR:#FFFF00">your text here</font>

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,979
    Something like this e.g. record 5

    Click image for larger version. 

Name:	RichTextForm.PNG 
Views:	26 
Size:	39.5 KB 
ID:	34942

    To do this, I have a memo field formatted in the table as rich text
    The form shows that field as rich text on the left & as plain text on the right so you can see the HTML code tags

    If that's what you want you should be able to use VBA to modify the appearance as required e.g. on button click
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    mredmond13 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    Louisiana, USA
    Posts
    16
    Quote Originally Posted by Ajax View Post
    If I've understood correctly I have to disagree. You can achieve something like this

    Click image for larger version. 

Name:	Capture.JPG 
Views:	27 
Size:	10.9 KB 
ID:	34941

    See this link

    https://www.access-programmers.co.uk...ight=rich+text

    for a small app so you can see the codes required

    but in principle you need

    <font style="BACKGROUND-COLOR:#FFFF00">your text here</font>
    This looks like exactly what I need. I'll give it shot and let you know.
    Thanks.

  6. #6
    mredmond13 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    Louisiana, USA
    Posts
    16
    Quote Originally Posted by ridders52 View Post
    Something like this e.g. record 5

    Click image for larger version. 

Name:	RichTextForm.PNG 
Views:	26 
Size:	39.5 KB 
ID:	34942

    To do this, I have a memo field formatted in the table as rich text
    The form shows that field as rich text on the left & as plain text on the right so you can see the HTML code tags

    If that's what you want you should be able to use VBA to modify the appearance as required e.g. on button click
    And this is even more than what I need. Thanks. I'll give them a try and let you know.

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,979
    On behalf of Ajax and myself, you're welcome.
    Its quite easy once you get the hang of it
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    mredmond13 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    Louisiana, USA
    Posts
    16
    Quote Originally Posted by ridders52 View Post
    On behalf of Ajax and myself, you're welcome.
    Its quite easy once you get the hang of it
    Can I complicate the questions a bit??

    In the effort to make this look kinda like a button, can the text have borders? In WORD, I can put borders around a word and recording a macro while doing it generates the code to do it. Can that be applied to Access?

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Of course, HTML <div> tag. Knew I should have done test before putting foot in mouth. Glad to be corrected.

    Now does div have border property? For tutorial on HTML visit https://www.w3schools.com/html/default.asp
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,979
    Quote Originally Posted by mredmond13 View Post
    Can I complicate the questions a bit??

    In the effort to make this look kinda like a button, can the text have borders? In WORD, I can put borders around a word and recording a macro while doing it generates the code to do it. Can that be applied to Access?
    Not sure what you mean - how about a screenshot?
    Access doesn't have a macro recorder
    If you want it to look like a button, why not use a ...button?! Or a label can be made to look like a button
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  11. #11
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    revised in next post

  12. #12
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    can the text have borders?
    html code should be the same if it exists, but whether an access richtext textbox will display it correctly I don't know, you'll have to try it. I think the word formatting is specific to Word and is similar to formatting borders around access controls - i.e. is not something that translates to html. Suggest save a word document with this feature as a html document, then inspect the underlying html code.

  13. #13
    mredmond13 is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2018
    Location
    Louisiana, USA
    Posts
    16
    Quote Originally Posted by ridders52 View Post
    Not sure what you mean - how about a screenshot?
    Access doesn't have a macro recorder
    If you want it to look like a button, why not use a ...button?! Or a label can be made to look like a button
    No, the macro recorder in WORD shows the code that word uses to put the border around a word. I'd like it to look something like the following:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	23 
Size:	2.2 KB 
ID:	34945
    I found a link that shows how to do it in HTML, but it applies to <p>. I couldn't make it work with <font>. Maybe some of you more experienced users know how.

    https://www.computerhope.com/issues/ch001392.htm

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Did some testing this time - div tag can have style element but border attribute isn't working in textbox. The RTF toolbar has an underscore (produces a <u> tag). There is a GRIDLINES icon on the ribbon Text Formatting toolbar which is disabled and that icon does not show on the RTF mini-toolbar. That icon is active for table/query/datasheet form. Possibly an outline box in textbox is beyond Access - too graphical.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #15
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,979
    As I understand it, rich text is a subset of HTML and not all HTML tags are supported
    I tried using the <span> tag but it didn't work : https://www.w3schools.com/html/html_blocks.asp

    TBH I think, if its possible to do, it would probably look a mess having text with a border inside a text box
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Multiple if statements on combobox background colors
    By themushroomking in forum Programming
    Replies: 3
    Last Post: 07-23-2016, 08:54 PM
  2. Replies: 3
    Last Post: 01-01-2014, 11:21 PM
  3. Change row-colors i subform datasheet view
    By rolfmagne in forum Forms
    Replies: 1
    Last Post: 03-02-2011, 11:07 AM
  4. Replies: 30
    Last Post: 03-01-2011, 10:05 AM
  5. Replies: 1
    Last Post: 12-30-2005, 10:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums