我正在做一个表格,很难根据文本框输入突出显示字段。我无法突出显示其中包含许多信息的字段。
这是我的输入字段, I search for "Family"
这是我的字段,里面有多个值,以逗号分隔
I cannot highlight the entire field eventhough the word "family" is in that field
有人知道如何解决这个问题吗? 使用vba后的表格 I searched for "words", this is the first record, it works fine
答案 0 :(得分:1)
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
要在移至下一条记录时重置文本框
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
输出