Hi,
I am a bit of a novice when it comes to Access, but have managed to create a form with a subform embedded and various filters to show different data within the subform, including a date range filter. The code I have used for these filters is as follows:
Private Sub Command40_Click()
Dim strCriteria As String
strCriteria = createCriteria("[Introductions].Town", "List78")
strCriteria = strCriteria & " and " & createCriteria("[Introductions].Ownership", "List52")
strCriteria = strCriteria & " and " & createCriteria("[Introductions].Company", "List54")
strCriteria = strCriteria & " and " & createCriteria("[Introductions].Sector", "List56")
strCriteria = strCriteria & " and " & createCriteria("[Introductions].Region", "List103")
With Me.sf4.Form
.Filter = strCriteria & " and " & "[Date] BETWEEN " & Format(Me.BeginDate, "\#mm\/dd\/yyyy\#") & " AND " & Format(Me.EndDate, "\#mm\/dd\/yyyy\#")
.FilterOn = True
End With
End Sub
This all works fine, but I'm wondering what I need to add to this code to make it so that if the date boxes are left blank, records from all dates are displayed. At the moment I have to enter dates in order for it to work properly.
I hope that makes sense! I'd really appreciate any help anyone could give me with this!
Thanks,
Clare
I am a bit of a novice when it comes to Access, but have managed to create a form with a subform embedded and various filters to show different data within the subform, including a date range filter. The code I have used for these filters is as follows:
Private Sub Command40_Click()
Dim strCriteria As String
strCriteria = createCriteria("[Introductions].Town", "List78")
strCriteria = strCriteria & " and " & createCriteria("[Introductions].Ownership", "List52")
strCriteria = strCriteria & " and " & createCriteria("[Introductions].Company", "List54")
strCriteria = strCriteria & " and " & createCriteria("[Introductions].Sector", "List56")
strCriteria = strCriteria & " and " & createCriteria("[Introductions].Region", "List103")
With Me.sf4.Form
.Filter = strCriteria & " and " & "[Date] BETWEEN " & Format(Me.BeginDate, "\#mm\/dd\/yyyy\#") & " AND " & Format(Me.EndDate, "\#mm\/dd\/yyyy\#")
.FilterOn = True
End With
End Sub
This all works fine, but I'm wondering what I need to add to this code to make it so that if the date boxes are left blank, records from all dates are displayed. At the moment I have to enter dates in order for it to work properly.
I hope that makes sense! I'd really appreciate any help anyone could give me with this!
Thanks,
Clare
Subform date filter that shows all values if left blank
0 commentaires:
Enregistrer un commentaire