Iam using the below code for filtering a data in a Subform, the filter works for dates in the current year. but if i include the from date starting 2018. it shows all the datas. kindly help.
If Len(txtFromDate) > 0 And Len(txtTodate) > 0 Then
If filterStr = "" Then
filterStr = filterStr & " ([ContDate] Between #" & txtFromDate & "# AND #" & txtTodate & "#)"
Else
filterStr = filterStr & " And ([ContDate] Between #" & txtFromDate & "# AND #" & txtTodate & "#)"
End If
ElseIf Len(txtFromDate) > 0 Then
If filterStr = "" Then
filterStr = filterStr & " ([ContDate] = #" & txtFromDate & "#)"
Else
filterStr = filterStr & " And ([ContDate] = #" & CDate(txtFromDate) & "#)"
End If
ElseIf Len(txtTodate) > 0 Then
If filterStr = "" Then
filterStr = filterStr & " ([ContDate] = #" & txtTodate & "#)"
Else
filterStr = filterStr & " And ([ContDate] = #" & CDate(txtTodate) & "#)"
End If
End If
Me.frmContList.Form.Filter = filterStr
If filterStr <> "" Then
Me.frmContList.Form.FilterOn = True
Else
Me.frmContList.Form.FilterOn = False
End If
If Len(txtFromDate) > 0 And Len(txtTodate) > 0 Then
If filterStr = "" Then
filterStr = filterStr & " ([ContDate] Between #" & txtFromDate & "# AND #" & txtTodate & "#)"
Else
filterStr = filterStr & " And ([ContDate] Between #" & txtFromDate & "# AND #" & txtTodate & "#)"
End If
ElseIf Len(txtFromDate) > 0 Then
If filterStr = "" Then
filterStr = filterStr & " ([ContDate] = #" & txtFromDate & "#)"
Else
filterStr = filterStr & " And ([ContDate] = #" & CDate(txtFromDate) & "#)"
End If
ElseIf Len(txtTodate) > 0 Then
If filterStr = "" Then
filterStr = filterStr & " ([ContDate] = #" & txtTodate & "#)"
Else
filterStr = filterStr & " And ([ContDate] = #" & CDate(txtTodate) & "#)"
End If
End If
Me.frmContList.Form.Filter = filterStr
If filterStr <> "" Then
Me.frmContList.Form.FilterOn = True
Else
Me.frmContList.Form.FilterOn = False
End If