To hinghlitht the searched words

  • Thread starter Frank Situmorang
  • Start date
F

Frank Situmorang

Hello,

My following VBA has worked to search the words on the text box. My qustion
is how can we make it to highlight the key words being searched.

This is my VBA

Private Sub TxtCari2_AfterUpdate()
'Dim strFilter As String
'Dim strSQL As String
Dim strFilter As String
'strSQL = "Select MOM.No_KEP, MOM.Subject, " _
'& "MOM.Nota From KepMajelisQry Where " & "MOM.Nota LIKE """ & "*" &
Me.Txtcari & "*" & """"

strFilter = "([Nota] LIKE """ & "*" & Me.TxtCari2 & "*" & """)"

'CurrentDb.Execute strSQL, dbFailOnError
'strSQL = strfilter
'Me.FilterOn = True
Me.Filter = strFilter
Me.FilterOn = True

End Sub

Thanks for any help.

Frank
 
A

Allen Browne

If you are using Access 2007, the text box is capable of supporting rich
text (it's HTML actually), so there is a way to highlight where the text was
found within a text box. Here's a demo of how:
Highlight matches - Matching characters of search results highlighted in
text box
at:
http://allenbrowne.com/AppSearchHighlight.html

If you are using an earlier version, the built-in text box can't do this. It
may be possible if you add custom rich text box such as this one from
Stephen Lebans:
http://www.lebans.com/richtext.htm
 
F

Frank Situmorang

Thanks Allen for your quick response. Since mine is A2K, I will try Leban's
sample.

Can you help me, how can we do it. I tried to open the form it says it is
not an object. should we import the module too into our module?.

Thanks in advance

Frank
Allen Browne said:
If you are using Access 2007, the text box is capable of supporting rich
text (it's HTML actually), so there is a way to highlight where the text was
found within a text box. Here's a demo of how:
Highlight matches - Matching characters of search results highlighted in
text box
at:
http://allenbrowne.com/AppSearchHighlight.html

If you are using an earlier version, the built-in text box can't do this. It
may be possible if you add custom rich text box such as this one from
Stephen Lebans:
http://www.lebans.com/richtext.htm

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Frank Situmorang said:
Hello,

My following VBA has worked to search the words on the text box. My
qustion
is how can we make it to highlight the key words being searched.

This is my VBA

Private Sub TxtCari2_AfterUpdate()
'Dim strFilter As String
'Dim strSQL As String
Dim strFilter As String
'strSQL = "Select MOM.No_KEP, MOM.Subject, " _
'& "MOM.Nota From KepMajelisQry Where " & "MOM.Nota LIKE """ & "*" &
Me.Txtcari & "*" & """"

strFilter = "([Nota] LIKE """ & "*" & Me.TxtCari2 & "*" & """)"

'CurrentDb.Execute strSQL, dbFailOnError
'strSQL = strfilter
'Me.FilterOn = True
Me.Filter = strFilter
Me.FilterOn = True

End Sub

Thanks for any help.

Frank
 
A

Allen Browne

I've not tried to use Stephen's control for this purpose, so I can't support
you through this process, Frank.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Frank Situmorang said:
Thanks Allen for your quick response. Since mine is A2K, I will try
Leban's
sample.

Can you help me, how can we do it. I tried to open the form it says it is
not an object. should we import the module too into our module?.

Thanks in advance

Frank
Allen Browne said:
If you are using Access 2007, the text box is capable of supporting rich
text (it's HTML actually), so there is a way to highlight where the text
was
found within a text box. Here's a demo of how:
Highlight matches - Matching characters of search results highlighted
in
text box
at:
http://allenbrowne.com/AppSearchHighlight.html

If you are using an earlier version, the built-in text box can't do this.
It
may be possible if you add custom rich text box such as this one from
Stephen Lebans:
http://www.lebans.com/richtext.htm

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.


Frank Situmorang said:
Hello,

My following VBA has worked to search the words on the text box. My
qustion
is how can we make it to highlight the key words being searched.

This is my VBA

Private Sub TxtCari2_AfterUpdate()
'Dim strFilter As String
'Dim strSQL As String
Dim strFilter As String
'strSQL = "Select MOM.No_KEP, MOM.Subject, " _
'& "MOM.Nota From KepMajelisQry Where " & "MOM.Nota LIKE """ & "*"
&
Me.Txtcari & "*" & """"

strFilter = "([Nota] LIKE """ & "*" & Me.TxtCari2 & "*" & """)"

'CurrentDb.Execute strSQL, dbFailOnError
'strSQL = strfilter
'Me.FilterOn = True
Me.Filter = strFilter
Me.FilterOn = True

End Sub

Thanks for any help.

Frank
 

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