Bold word in a setences on a report (1 Viewer)

amir0914

Registered User.
Local time
Today, 12:31
Joined
May 21, 2018
Messages
151
Hello All,
I've create a report that is included two columns, first columns is words and second is sentences (example for word).

Word | Example
..................................................
Ensure | The airline is taking steps to ensure safety on its aircraft.
invent | Pneumatic tyres were invented in 1888 by John Dunlop.
devote | He devoted his life to serving his family, friends, and neighbors.

* Now I want to make bold the word in the sentence on report when printing , like this :

Ensure | The airline is taking steps to ensure safety on its aircraft.
invent | Pneumatic tyres were invented in 1888 by John Dunlop.

Is there a way to accomplish it ?
 
Last edited:

amir0914

Registered User.
Local time
Today, 12:31
Joined
May 21, 2018
Messages
151
Yes. Use a long text field and set it to rich text format.
Thank for your respond.,
It was Long text and I just change it to Rich text.
So what do i do for the next step ? how to show bold the word within the text on the report ?
 

isladogs

MVP / VIP
Local time
Today, 20:31
Joined
Jan 14, 2017
Messages
18,239
Reports are not designed for user interaction though some limited editing is possible in report view.
Do the formatting with the popup rich text toolbar or the ribbon using a form on the underlying table or query
See my example app
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:31
Joined
Sep 21, 2011
Messages
14,315
I did mine in the source of the report?
Code:
SELECT qryRankCrewShipIssue.Ship, qryRankCrewShipIssue.Issue, qryRankCrewShipIssue.On_Date, "<strong>" & [Rank.Rank] & ": " & "</strong>" & SimpleCSV("SELECT RankNames FROM QryRankCrew WHERE [Ship]='" & [Ship] & "' AND [Rank]= '" & [Rank.Rank] & "' AND [Issue]=" & [Issue],", ") AS ConcatRanksNames, Rank.Sequence, qryRankCrewShipIssue.Rank
FROM qryRankCrewShipIssue INNER JOIN Rank ON qryRankCrewShipIssue.Rank = Rank.Rank
ORDER BY Rank.Sequence;
1657612408600.png


However, I was only highlightin Crew Rank.
I think you are going to have problems when the names to not match entirely, IE Invent and invented.
Will probably need a dedicated function to get what you want.
 

amir0914

Registered User.
Local time
Today, 12:31
Joined
May 21, 2018
Messages
151
Thank you both, I think it can be done directly on report without changing table foramts, I write a simple function in an unbound textbox (Rich Format) on the report, but it's not complete:

Code:
=Left([WordExample],InStr(1,[WordExample],[Word])-1) & "<b> " & [Word] & " </b>"

Screenshot (66).png


As you can see I could get the text till the word by the function. Can someone complete the function to show the rest of the text (after the bold word) ??
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 20:31
Joined
Jan 14, 2017
Messages
18,239
Use Mid for the rest of the sentence. But much easier to edit the source data in a form.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:31
Joined
May 7, 2009
Messages
19,245
you can use Replace$() function:

=Replace$([WordExample], [Word], "<b>" & [Word] & "</b>")
 

amir0914

Registered User.
Local time
Today, 12:31
Joined
May 21, 2018
Messages
151
you can use Replace$() function:

=Replace$([WordExample], [Word], "<b>" & [Word] & "</b>")
Great!
But as Gasman mentioned I have problem with the words that is not math with the sentence, like :

invent | Pneumatic tyres were invented in 1888 by John Dunlop.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:31
Joined
Feb 19, 2013
Messages
16,618
the way to solve that is to include spaces a each end

=Replace([WordExample], " " & [Word] & " ", " <b>" & [Word] & "</b> ")

but that leaves you with the problem of if the word is the first or last word of the sentence - so add spaces there as well

=Replace(" " & [WordExample] & " ", " " & [Word] & " ", " <b>" & [Word] & "</b> ")

but then you need to remove the prefix and suffix spaces and also consider if a sentence ends in a full stop or the word is followed by a comma, colon or semi colon - or even preceded with one of these characters without a space.

The other consideration is if the word is the first one of a sentence, it starts with a capital - so are you happy to replace 'Invent' with 'invent'?

Think you need to be much clearer about the overall requirement rather than addressing this piecemeal.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:31
Joined
May 7, 2009
Messages
19,245
create these two functions in a Module:
Code:
' arnelgp
Public Function MakeBold(ByVal theWord As String, ByVal theSentence As String)
Dim var, v
var = ArrayContainingSubStr(theSentence, theWord)
If IsArray(var) Then
    For Each v In var
        theSentence = Replace$(theSentence, v, "<b>" & v & "</b>")
    Next
End If
MakeBold = theSentence
End Function

'arnelgp
Public Function ArrayContainingSubStr( _
                            strIn As String, strFind As String, Optional strJoinDelim As String = " ") As Variant
' Return aarray of string containing all the words
' in the input string containing a supplied substring.
Dim astrItems() As String
Dim astrFound() As String
    If Len(strIn) > 0 And Len(strFind) > 0 Then
        astrItems = Split(strIn)
        ArrayContainingSubStr = Filter(astrItems, strFind, True, vbTextCompare)
    Else
        ArrayContainingSubStr = strIn
    End If
End Function

to use:

=MakeBold([Word], [Example])

see this sample Report.
 

Attachments

  • replaceword.accdb
    540 KB · Views: 126
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 20:31
Joined
Feb 19, 2013
Messages
16,618
Just realised the OP has a word ‘invent’ but wants ‘invented’ to be highlighted. Easy enough to fix in arnel’s code but what about looking for ‘nation’ and finding the word ‘international’? Or looking for ‘craft’ and finding ‘witchcraft’ and ‘crafty’ and ‘aircraft’
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:31
Joined
Sep 21, 2011
Messages
14,315
My thoughts were to find the word, then find a space either side of that position and take all of that to be made bold.?
 

amir0914

Registered User.
Local time
Today, 12:31
Joined
May 21, 2018
Messages
151
create these two functions in a Module:
Code:
' arnelgp
Public Function MakeBold(ByVal theWord As String, ByVal theSentence As String)
Dim var, v
var = ArrayContainingSubStr(theSentence, theWord)
If IsArray(var) Then
    For Each v In var
        theSentence = Replace$(theSentence, v, "<b>" & v & "</b>")
    Next
End If
MakeBold = theSentence
End Function

'arnelgp
Public Function ArrayContainingSubStr( _
                            strIn As String, strFind As String, Optional strJoinDelim As String = " ") As Variant
' Return aarray of string containing all the words
' in the input string containing a supplied substring.
Dim astrItems() As String
Dim astrFound() As String
    If Len(strIn) > 0 And Len(strFind) > 0 Then
        astrItems = Split(strIn)
        ArrayContainingSubStr = Filter(astrItems, strFind, True, vbTextCompare)
    Else
        ArrayContainingSubStr = strIn
    End If
End Function

to use:

=MakeBold([Word], [Example])

see this sample Report.
Perfect!!
Thank you all for spending time on my issue.
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:31
Joined
May 7, 2009
Messages
19,245
modified code to only return if the Root word of extracted string match the [Word].
 

Attachments

  • replaceword.accdb
    736 KB · Views: 98
Last edited:

Users who are viewing this thread

Top Bottom