I have the following code in my database that searches through all my records for certain keywords and prints out a report that has each record that has the keyword in it. I want to highlight the keyword in the report to make it easier to find in each record. Is this possible?
Code:
Dim dbCurr As DAO.Database
Dim qdfCurr As DAO.QueryDef
Dim rsSearch As DAO.Recordset
Dim strSearch As String
Dim sqlStr As String
Dim reportName As String
Dim queryName As String
reportName = "Search Keyword Report"
queryName = "Search Keyword Query"
If IsNull(Me.txtNarrativeKeySrch) Or Me.txtNarrativeKeySrch = "" Then
MsgBox "Please type in your keyword.", vbOKOnly, "Keyword Needed"
Me.txtNarrativeKeySrch.Backcolor = vbYellow
Me.txtNarrativeKeySrch.SetFocus
Else
strSearch = Me.txtNarrativeKeySrch.Value
Set dbCurr = CurrentDb()
Set qdfCurr = dbCurr.QueryDefs(queryName)
sqlStr = "SELECT [Cnf].* " _
& "FROM [Cnf] " _
& "WHERE ([Cnf].[Operational Gap] Like '*" & strSearch & "*' OR " _
& "[Cnf].[Needed Capability] Like '*" & strSearch & "*' OR " _
& "[Cnf].[OP Impact if Unfulfilled] Like '*" & strSearch & "*' OR " _
& "[Cnf].[Potential Solutions] Like '*" & strSearch & "*' OR " _
& "[Cnf].[Prior Resolution Attempts] Like '*" & strSearch & "*' OR " _
& "[Cnf].[Need By Narrative] Like '*" & strSearch & "*' OR " _
& "[Cnf].[Required Use Narrative] Like '*" & strSearch & "*' OR " _
& "[Cnf].[LTCON Narrative] Like '*" & strSearch & "*' OR " _
& "[Cnf].[Title] Like '*" & strSearch & "*' OR " _
& "[Cnf].[J38RQ Notes] Like '*" & strSearch & "*' OR " _
& "[Cnf].[FARWG Notes] Like '*" & strSearch & "*' OR " _
& "EXISTS (SELECT [CnfToAdditionalDetail].[Additional Detail], [CNF ID#] " _
& "FROM [Cnf] LEFT JOIN [CnfToAdditionalDetail] ON [Cnf].[CNF ID#] = [CnfToAdditional Details].[CNF ID#] " _
& "WHERE ([CnfToAdditionalDetail].[AdditionalDetails] Like '*" & strSearch & "*' AND NOT EXISTS (" _
& "SELECT [Cnf].* " _
& "FROM [Cnf] " _
& "WHERE ([Cnf].[Operational Gap] Like '*" & strSearch & "*' OR [Cnf].[Needed Capability] Like '*" & strSearch & "*' OR " _
& "[Cnf].[OP Impact if Unfulfilled] Like '*" & strSearch & "*' OR [Cnf].[Potential Solutions] Like '*" & strSearch & "*' OR " _
& "[Cnf].[Prior Resolution Attempts] Like '*" & strSearch & "*' OR [Cnf].[Need By Narrative] Like '*" & strSearch & "*' OR " _
& "[Cnf].[Required Use Narrative] Like '*" & strSearch & "*' OR [Cnf].[LTCON Narrative] Like '*" & strSearch & "*' OR " _
& "[Cnf].[Title] Like '*" & strSearch & "*' OR [Cnf].[J38RQ Notes] Like '*" & strSearch & "*' OR " _
& "[Cnf].[FARWG Notes] Like '*" & strSearch & "*' " _
& "))))) "
Me.txtNarrativeKeySrch.BackColor = VbWhite
Me.txtNarrativeKeySrch.Value = ""
qdfCurr.SQL = sqlStr
DoCmd.OpenReport reportName, acViewReport, queryName, , acWindowNormal
qdfCurr.Close
Set qdfCurr = Nothing
Set dbCurr = Nothing
End If