Results 1 to 12 of 12
  1. #1
    Chronus13 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    24

    Text Color

    So, I have a report that shows a field called "Nomenclature" among many others. The data is carried over from a query. What I am trying to accomplish is I ONLY want to take certain words in that "Nomenclature" field and color it red. Example would be " Hammer (PEENED)" The words that would be colored red are: ADHESIVE, PEENED and/or SPOT WELDED (or any combination of). I am not very good with coding or expressions, hence still learning. Saying this, any help is greatly appreciated.

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    I would use conditional formatting on the report field. Ribbon>Format>Control Formatting when in report design view.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Chronus13 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    24
    Micron,
    I have a very limited understanding of expressions and such to begin with. I tried to use different methods using the conditional formatting but I obviously cannot figure out how to do it lol. I tried the = to and the all the other options but nothing works, either it colors the whole field or it colors odd rowed fields lol. If I am supposed to use the expression area, I would need some help there. I would appreciate the help.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    CF will affect the whole text, you just want part of the text.?
    The links I posted should show you what you need to do?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    a field called "Nomenclature"
    I ONLY want to take certain words in that "Nomenclature" field and color it red
    To me that means the field only contains the keywords, such as "peened".
    it colors the whole field
    I understood your post to mean that the field you want to color the text in only contained those values, so that should work. If that's not what you have, then I'd say the field has to be formatted as rtf in the table, and so does your form control. Then you should be able to apply limited formatting as you're entering the data in the field.

    Perhaps you should clear up the uncertainty if that doesn't help.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Chronus13 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    24
    Click image for larger version. 

Name:	Sample.gif 
Views:	17 
Size:	20.2 KB 
ID:	48681Micron, the whole field includes other words as you can see in the picture (if I posted it correctly). The words ADHESIVE, PEENED or SPOT WELDED will be in parentheses and I am looking at only coloring those three words red out of the whole string of words and not color the rest and no highlighting. I tried using the different options but the results were random colorings of the whole string of text. If I picked = to, it didn't color anything red. I tried the < or = to and the > version and still no luck. I know this has to be something easily accomplished and I just don't seem to grasp it atm.

  8. #8
    Chronus13 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    24
    Welshgasman,
    I apologize but those links didn't help me, I honestly think understanding them was a bit hard for me. Still a beginner. Much appreciated though.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Well the basics are that you have to surround the word with the requisite html tags and the field hast to be rtf, which I believe means a memo field.
    There are examples there.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Chronus13 is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    24
    Welshgasman,
    OK, could it be something like this:

    Private Sub NOMENCLATURE_BeforeUpdate(Cancel As Integer)
    If Me![NOMENCLATURE] = "PEENED" Then
    Me![NOMENCLATURE].BackColor = vbWhite
    Me![NOMENCLATURE].FontBold = True
    Me![NOMENCLATURE].ForeColor = vbRed
    Else
    Me![NOMENCLATURE].BackColor = vbWhite
    Me![NOMENCLATURE].FontBold = True
    Me![NOMENCLATURE].ForeColor = vbBlack
    End If
    End Sub

    I know it doesn't work, but am I close? I have a feeling that the issue is that all the formulas I am trying are not going to work because it all asks for equal, not equal, greater than or less than. None of the examples I can find show anything about containing. Because my field doesn't just have the 3 words I mentioned, but other text as well?

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Quote Originally Posted by Chronus13 View Post
    Welshgasman,
    OK, could it be something like this:

    Private Sub NOMENCLATURE_BeforeUpdate(Cancel As Integer)
    If Me![NOMENCLATURE] = "PEENED" Then
    Me![NOMENCLATURE].BackColor = vbWhite
    Me![NOMENCLATURE].FontBold = True
    Me![NOMENCLATURE].ForeColor = vbRed
    Else
    Me![NOMENCLATURE].BackColor = vbWhite
    Me![NOMENCLATURE].FontBold = True
    Me![NOMENCLATURE].ForeColor = vbBlack
    End If
    End Sub

    I know it doesn't work, but am I close? I have a feeling that the issue is that all the formulas I am trying are not going to work because it all asks for equal, not equal, greater than or less than. None of the examples I can find show anything about containing. Because my field doesn't just have the 3 words I mentioned, but other text as well?
    Well not really for what you originally asked for.
    You would need to search the control for your required words?

    For that look at Instr(). If it returns a value greater than zero, then that word is contained within that control.

    However that will still highlight the whole control value?

    I would probably write a function to do this.

    The function would be passed the control value and the word to search for.
    If your value from Instr() is > 0 then I would get the left of the string using that value.
    You will know the value of the length of the required word, so calculate and use Mid() to get the rest of the value of the control.
    So now you have LeftPart and RightPart of the string and know the word.
    Then concatenate back as LeftPart & required start code & RequiredWord & required end code & RightPart

    Set that to the name of the function and exit.
    Set the control value back to the returned value for that function.

    I did something similar for a report control (again, needs to be a memo field) so that the rank of the crew would be bold amongst the rest of the data.
    I needed bold, which is shown by the strong html tag.

    I constructed the html and data in a query for the report and the bibby pic shows the result, which is used at https://www.bibby-gazette.co.uk/dates.html

    Again that link shows you how with the codes?

    HTH
    Attached Thumbnails Attached Thumbnails html tag data.PNG   bibby.PNG  
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  12. #12
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    No, you're not close. AFAIK if you want this to be dynamic and done with code, you're going to have to
    - move to a record
    - test if the field contains one of your keywords. If not, move on to the next record (unless you're selecting records manually, then there's no movement)
    - if true, get the string value up to that keyword, concatenate your rtf formatting to that (the beginning tags)
    - find the end of the keyword (I think you also need to know what the keyword is, not just if any one of them is present) and append the closing tags to that
    - then concatenate the rest of the field. Difficulty can be compounded because although rtf tags are not visible, they are part of the string. So if you concatenate tags, the string length changes, so you cannot go by any calculations that you've already done. As stated, the control has to be rtf formatted (oddly, that property is on the Data tab of properties form) and the table field has to be memo (long text) and rtf formatted.

    You could save yourself a lot of effort if you could simply set up as noted and use formatting from the ribbon by first selecting the word to be formatted.

    Consider
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. change text box color if its null
    By aamer in forum Access
    Replies: 6
    Last Post: 06-24-2018, 08:09 AM
  2. Change Text color and/or background color
    By Thompyt in forum Reports
    Replies: 2
    Last Post: 02-23-2017, 07:08 PM
  3. Rich text - text color and size
    By Subs in forum Reports
    Replies: 3
    Last Post: 11-08-2013, 10:36 AM
  4. Add color to text based on Value
    By tngirl in forum Reports
    Replies: 1
    Last Post: 05-23-2013, 01:17 PM
  5. Text box change color
    By Ray67 in forum Forms
    Replies: 14
    Last Post: 11-19-2012, 04:06 PM

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