
Originally Posted by
CarlettoFed
The code you posted doesn't do what you initially asked for, ie if Me.txtClerkFilter is null it must not consider what is written in Me.txtCitNumFilter.
For the problem of dates you should first read something about how filters are managed based on the type of data on which the search must be performed, in the forums or other you can find infinite cases where it is explained.
Furthermore, the Like type search cannot be used in Date type fields, it should not be used in the Numeric field but only in the Text type and in indispensable cases as it is very costly in terms of response times.
Thank you very much for your time and trying to help me on these issues. On a technical point you are probably right. However, I have done some testing on my final version of this code and it seems to work exactly how I want regardless of the things you mentioned. I need to get this done soon and do not have the time to go researching as of right now. I may in the future but I really was hoping for someone that is very good at writing VBA to write something up for me the correct way. So unless you can rewrite this code and make it work how it's technically supposed to, I think this will have to do for now. Load times for filtering do not seem bad at the moment and I am dealing with about 58k records on a test environment. I don't see this ever going over 100k as I do archive records every year. So I am happy with what I have for now unless I get any glitches down the road, I'll be back to seek help. For now, this is the final code that seems to be working exactly how I want it:
Code:
Dim searchfor As String
If Not IsNull(Me.txtClerkFilter) Then
searchfor = " AND [Clerk] like ""*" & Me.txtClerkFilter & "*"""
End If
If Not IsNull(Me.txtCitNumFilter) Then
searchfor = searchfor & " AND [Citation Num] Like ""*" & Me.txtCitNumFilter & "*"""
End If
If Not IsNull(Me.txtRefFilter) Then
searchfor = searchfor & " AND [Ref Num] Like ""*" & Me.txtRefFilter & "*"""
End If
If Not IsNull(Me.txtCustNamFilter) Then
searchfor = searchfor & " AND [Customer Name] Like ""*" & Me.txtCustNamFilter & "*"""
End If
' if both date fields are entered
If Not IsNull(Me.txtStartFilter) And Not IsNull(Me.txtEndFilter) Then
searchfor = searchfor & " AND [Date Of Service] Between #" & Nz(Me.[txtStartFilter], _
"1/1/1900") & "# AND #" & Nz(Me.[txtEndFilter], "12/31/2900") & "#"
End If
' if only start date is entered
If Not IsNull(Me.txtStartFilter) And IsNull(Me.txtEndFilter) Then
searchfor = searchfor & " AND [Date Of Service] Like ""*" & Me.txtStartFilter & "*"""
End If
' if only end date is entered
If Not IsNull(Me.txtEndFilter) And IsNull(Me.txtStartFilter) Then
searchfor = searchfor & " AND [Date Of Service] Like ""*" & Me.txtEndFilter & "*"""
End If
If Not IsNull(Me.cmbSubjectFilter) Then
searchfor = searchfor & " AND [Subject] Like ""*" & Me.cmbSubjectFilter & "*"""
End If
If Not IsNull(Me.txtDLNumFilter) Then
searchfor = searchfor & " AND [DL Num] Like ""*" & Me.txtDLNumFilter & "*"""
End If
If Not IsNull(Me.txtPlateFilter) Then
searchfor = searchfor & " AND [Plate Num] Like ""*" & Me.txtPlateFilter & "*"""
End If
If searchfor = "" Then
Me.Filter = ""
Me.FilterOn = False
Else
Me.Filter = Mid(searchfor, 6)
Me.FilterOn = True
End If