Answered by:
Highlighting fields found in a find function

Question
-
I want to be able to highlight multiple occurrences of text selected with a find function. I have the following but it is not giving me the intended results.
Private Sub cmdFind_Click()'Declare procedure variables
Dim strText As String
Dim intCharPositionFound As Integer
Dim rst As Recordset
'Get text to search for from user
strText = InputBox("Enter text to find in Notes field.")
If strText = "" Then
Exit Sub
End If
'Search for text and highlight if found
Do
intCharPositionFound = InStr([Finding Continued], strText)
If intCharPositionFound > 0 Then
With [Finding Continued]
.SetFocus
.SelStart = intCharPositionFound - 1
.SelLength = Len(strText)
End With
End If
MsgBox "Do you want to find more", vbOKCancel, "Highlights"
Loop While Not rst.EOF
End Sub
Dean J. Waring
Friday, October 7, 2016 7:20 PM
Answers
-
I am searching memo fields and text boxes. Is there a downside to setting the memo field to Rich Text format?
Dean J. Waring
In my humble opinion, the only downside is you can't go back to plain text if you need to later on.- Proposed as answer by David_JunFeng Friday, October 14, 2016 9:40 AM
- Marked as answer by David_JunFeng Monday, October 17, 2016 2:38 PM
Friday, October 7, 2016 7:57 PM
All replies
-
Hi Dean,
Are you searching a Memo field? If so, you may be able to take advantage of Rich Text formatting. However, once a memo field is set to use Rich Text format, it cannot be removed again.
Just a thought...
Friday, October 7, 2016 7:39 PM -
I am searching memo fields and text boxes. Is there a downside to setting the memo field to Rich Text format?
Dean J. Waring
Friday, October 7, 2016 7:52 PM -
I am searching memo fields and text boxes. Is there a downside to setting the memo field to Rich Text format?
Dean J. Waring
In my humble opinion, the only downside is you can't go back to plain text if you need to later on.- Proposed as answer by David_JunFeng Friday, October 14, 2016 9:40 AM
- Marked as answer by David_JunFeng Monday, October 17, 2016 2:38 PM
Friday, October 7, 2016 7:57 PM -
I don't think its possible to "highlight" multiple substrings in that manor. Thats like trying to highlight multiple things with your mouse cursor. Your attempting to select multiple substrings as once.
I do think DBGuy is on the right track, use controls or table fields that accept Rich Text formatting, and HTML Rich Text encodings to do the highlighting instead of the .Sel methods.
Just a side comment. I just tried converting a Long Text field to Rich Text on a table, made some entries with color formatted text, then changing it back to Plain Text. It did worked for me.
I'm using MS Access 2016. If earlier versions don't allow that, your not out of luck. Copy to a temp field, use the PlainText function in an Update statement, delete old field and rename temp field.
Friday, October 7, 2016 9:22 PM