Highlighting text, memo field. Code sample works, But can it be mo

B

BrianPaul

I went to Access 2007 from 2003, Was impressed with some of the code samples
from various MVP sites. One impressed me imparticular that I liked and
adapted great to my app searching through memo fields and highlighting in red
when it found the match.

On Error GoTo Err_Handler
'Purpose: Filter, and highlight matches in txtSearchDisplay.
Dim strField As String 'The field to search
Dim strSearchValue As String 'The value to find
Dim strControlSource As String 'ControlSource for displaying match.
Const strcWildcard = "*" 'Some other back ends use %
'HTML tags for highlighting matches. Could be just "<b>" and "</b>".
Const strcTagStart = "<font color=""""red"""">"
Const strcTagEnd = "</font>"

'Save any edits.
If Me.Dirty Then
Me.Dirty = False
End If

'Apply a filter only if user chose a field and a value.
If IsNull(Me.cboField) Or IsNull(Me.txtSearchText) Then
If Me.FilterOn Then
Me.FilterOn = False
End If
Call ShowHide(Me.txtSearchDisplay, False)
Else
strField = "[" & Me.cboField & "]" 'Cope with spaces in field name.
strSearchValue = Me.txtSearchText
'Apply the filter
Me.Filter = strField & " Like """ & strcWildcard & strSearchValue &
strcWildcard & """"
Me.FilterOn = True

'Control Source for the text box to display matches.
strControlSource = "=IIf(" & strField & " Is Null, Null, " & _
"Replace(" & strField & ", """ & strSearchValue & """, """ & _
strcTagStart & strSearchValue & strcTagEnd & """))"
With Me.txtSearchDisplay
.ControlSource = strControlSource
.Visible = True
End With
End If


Question, If I use the Like statement in a query under a field like I used
to In access 2003, Could I still use the like statement in a query, Do away
with the combo box, and still have the code work. For example: I would put
the like statement in a query, bound the form to the query, Open the form, It
would prompt me for the search criteria, Enter in text I was looking for, It
would show me those records I searched. Would be cool If I could do the same
thing but take advantage of the New feature in Access 2007. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top