Private Sub Command48_Click()
'remove format condition
Call FormFormatCondition
If Nz(Me.SearchBox, vbNullString) = vbNullString Then
MsgBox "No search term entered!"
ElseIf DCount("Mrecordid", "Search") = 0 Then
' Check if number of records is zero and display message instead of filtering to no records
MsgBox " Nothing found using that search term! "
Me.SearchBox = vbNullString
Me.SearchBox.SetFocus
Exit Sub
Else
Me.RecordSource = "Search"
'add format condition
Call FormFormatCondition(Me.SearchBox)
End If
End Sub
'arnelgp
Private Function FormFormatCondition(Optional ByVal strText As String = "")
Dim c As Access.Control
Dim cf As Access.FormatCondition
If Len(strText) = 0 Then
'remove conditional format
On Error Resume Next
For Each c In Me.Controls
If "TextboxComboboxListbox" Like "*" & TypeName(c) & "*" Then
c.FormatConditions.Delete
End If
Next
Else
'add conditional format
For Each c In Me.Controls
If "TextboxComboboxListbox" Like "*" & TypeName(c) & "*" Then
Set cf = c.FormatConditions.Add(1, 2, "[" & c.ControlSource & "] Like '*" & strText & "*'")
cf.BackColor = vbYellow
End If
Next
End If
'end of arnelgp
End Function