SparkieDEV
New member
- Local time
- Today, 17:46
- Joined
- Oct 13, 2020
- Messages
- 26
Hi All,
I have been working on making improvements to an Asset Management Database that I have been building for some months now. I am finding it quite difficult to create a dynamic search filter using a text box to search both text and date fields on a KeyUp function. I would like your help please:
I am searching multiple fields as you can see below, most of them are text fields. I am however unable to find a solution that works when ALSO searching for a date within the textbox [AuditDate].
.Format(AuditDate,"dd/mm/yy") Like
doesn't work.
Thank you in advance.
I have been working on making improvements to an Asset Management Database that I have been building for some months now. I am finding it quite difficult to create a dynamic search filter using a text box to search both text and date fields on a KeyUp function. I would like your help please:
I am searching multiple fields as you can see below, most of them are text fields. I am however unable to find a solution that works when ALSO searching for a date within the textbox [AuditDate].
.Format(AuditDate,"dd/mm/yy") Like
doesn't work.
Thank you in advance.
Code:
Private Sub TB_AuditSearch_KeyUp(KeyCode As Integer, Shift As Integer)
On Error GoTo errHandler
Dim filterText As String
'Apply or update filter based on user input.
If Len(TB_AuditSearch.Text) > 0 Then
filterText = TB_AuditSearch.Text
Me.Form.Filter = "[TBLAuditDB]![AUDITID] LIKE '*" & filterText & "*' OR [TBLAuditDB]![AuditDate] LIKE '*" & filterText & "*' OR [TBLAuditDB]![AssetName] LIKE '*" & filterText & "*' OR [TBLAuditDB]![REF] LIKE '*" & filterText & "*' OR [TBLAuditDB]![Type] LIKE '*" & filterText & "*' OR [TBLAuditDB]![Status] LIKE '*" & filterText & "*' OR [TBLAuditDB]![RAGID] LIKE '*" & filterText & "*' OR [TBLAuditDB]![Period] LIKE '*" & filterText & "*'"
Me.FilterOn = True
'Retain filter text in search box after refresh.
TB_AuditSearch.Text = filterText
TB_AuditSearch.SelStart = Len(TB_AuditSearch.Text)
Else
' Remove filter.
Me.Filter = ""
Me.FilterOn = False
TB_AuditSearch.SetFocus
End If
Exit Sub
errHandler:
MsgBox Err.Number & " - " & Err.Description, vbOKOnly, "Error ..."
End Sub