Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2011
    Posts
    2

    Question how to highlight search keywords in results form?


    Hi everybody,

    I've been tasked with improving a database, which includes a search form. The code of the search form reads as follows:

    Code:
     
    Private Sub Command_Go_Click()
        Dim strSearch As String
        Dim strSQL As String
        Dim strMatches As String
        Dim rst As DAO.Recordset
        Dim fld As DAO.Field
        Dim i As Integer
     
        If IsNull(Me.Text_Search.Value) Then
       MsgBox "Bitte geben Sie einen Suchbegriff ein!"
       Text_Search.SetFocus
       End If
     
        If Len(Nz(Me.Text_Search.Value, "")) Then
            strSearch = "*" & Trim(Me.Text_Search.Value) & "*"
            strSQL = "SELECT tblSitzung.sitzung_id " & _
                          ", tblSitzung.sitzung_datum " & _
                          ", tblSitzung.sitzung_art " & _
                          ", tblSitzung.sitzung_teilnehmer " & _
                          ", tblThemen.themen_id " & _
                          ", tblThemen.themen_fragestellung " & _
                          ", tblThemen.themen_input " & _
                          ", tblThemen.themen_ergebnis " & _
                       "FROM tblSitzung INNER JOIN tblThemen ON tblSitzung.sitzung_id=tblThemen.sitzung_id_f;"
            Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
            With rst
                Do Until .EOF
                    For Each fld In .Fields
                        If Nz(fld, "") Like strSearch Then
                            If Not InStr(strMatches, rst!sitzung_id) Then
                                If Len(strMatches) > 0 Then strMatches = strMatches & ", "
                                strMatches = strMatches & !sitzung_id
                            End If
                        End If
                    Next fld
                    .MoveNext
                Loop
                .Close
            End With
            Set rst = Nothing
            If Len(strMatches) Then
                DoCmd.OpenForm "frmSitzung", , , "sitzung_id IN ( " & strMatches & " )"
                Forms!frmSitzung.[Unterformular].Form.Filter = "[themen_fragestellung] LIKE '*" & Me.Text_Search.Value & "*' OR [themen_input] LIKE '*" & Me.Text_Search.Value & "*' OR [themen_ergebnis] LIKE '*" & Me.Text_Search.Value & "*'"
                Forms("frmSitzung").Sought = Me.Text_Search.Value
                Forms!frmSitzung.AllowEdits = False
                Forms!frmSitzung!Unterformular.Form.AllowEdits = False
            Else
                MsgBox "Keine Ergebnisse für den Suchbegriff:  " & Me.Text_Search.Value, vbInformation, "Suche abgeschlossen"
                Text_Search.SetFocus
            End If
        End If
     
     
    End Sub
    I’d now like the search keywords that were found in the database to be highlighted in the results form. Could anybody help me out with the code for that? Your assistance would be greatly appreciated.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    I haven't played with this before but the only way I think you can do this is if you are displaying the results of your search on a form, then you might be able to do some conditional formatting. I haven't tried to do conditional formatting with code.

    http://msdn.microsoft.com/en-us/libr...ffice.10).aspx

    This is a link to an article about applying conditional formatting with code.

  3. #3
    Join Date
    Aug 2011
    Posts
    2

    thanks

    Thank you very much for your assistance!

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

Similar Threads

  1. Replies: 12
    Last Post: 06-08-2012, 02:37 AM
  2. Replies: 4
    Last Post: 09-22-2010, 01:47 AM
  3. How to Search for keywords in a Query
    By Brian62 in forum Queries
    Replies: 2
    Last Post: 05-24-2010, 11:14 AM
  4. Search Form Results Displayed In Report
    By warrenjburns in forum Forms
    Replies: 1
    Last Post: 03-18-2009, 02:08 AM
  5. Replies: 0
    Last Post: 10-16-2008, 02:39 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