Reputation: 13
I have a form where i created two text boxes to choose the start and end date and a button to filter the table in the form by the dates chosen.
My vba code does not work. Can someone help?
This is the code:
Private Sub Command150_Click()
If IsNull(Me.Text153) And IsNull(Me.Text155) Then
Me.FilterOn = False
Else
Me.Filter = "[Datum] BETWEEN #" & Me.Text153 & "# AND #" & Me.Text155 & "#"
Me.FilterOn = True
End If
End Sub
Note: Text153 is start date, Text 155 is end date, Datum is the field in the table which is filtered. The dates filtered should be >= Start date and <= End date.
Upvotes: 1
Views: 1280
Reputation: 55806
Datum sounds German, so you may have to force a slash as the date separator:
Private Sub Command150_Click()
Dim Filter As String
If IsNull(Me.Text153) Or IsNull(Me.Text155) Then
Me.FilterOn = False
Else
Filter = "[Datum] BETWEEN #" & Format(Me.Text153, "yyyy\/mm\/dd") & "# AND #" & Format(Me.Text155, "yyyy\/mm\/dd") & "#"
' Print the filter string to the Immediate window (press Ctrl+G).
Debug.Print Filter
Me.Filter = Filter
Me.FilterOn = True
End If
End Sub
Upvotes: 1