how to highlight search keywords in results form?

Absolute_Beginner

Registered User.
Local time
Today, 11:28
Joined
Aug 3, 2011
Messages
10
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.
 

Users who are viewing this thread

Back
Top Bottom