Reputation: 27
I'm doing a form and having difficulty in highlighting field based on textbox input. I cannot highlight the field that contains many information in it.
This is my input field, I search for "Family"
This is my field where I have multiple values in it, separated by comma
I cannot highlight the entire field eventhough the word "family" is in that field
Anyone got idea how to solve this? My form after using vba I searched for "words", this is the first record, it works fine
Upvotes: 2
Views: 453
Reputation: 12353
Private Sub cmdSearch_Click()
Dim ctrl As Control
If Nz(Me.txtSearch, "") <> "" Then
For Each ctrl In Me.Controls
If TypeName(ctrl) = "TextBox" And ctrl.Name <> "txtSearch" Then
If InStr(1, ctrl, Me.txtSearch, vbTextCompare) > 0 Then
ctrl.BackColor = vbRed
Else
ctrl.BackColor = vbWhite
End If
End If
Next
End If
End Sub
To reset textboxes on moving to next record
Private Sub Form_Current()
Dim ctrl As Control
'Me.txtSearch = ""
For Each ctrl In Me.Controls
If TypeName(ctrl) = "TextBox" Then
ctrl.BackColor = vbWhite
End If
Next
cmdSearch_Click
End Sub
output
Upvotes: 1