Reputation: 15
This is the code I am using in order to try and filter a forms subform according to the dates in the txt boxes. The code is having a compile error, stopping at the third # with a "expect expression" and I can't figure out why. I got this code from another location and simply tried to use it for my purposes. I know nothing about vba.
Private Sub btnDateRange_Click()
Me.Filter = "[tblDeliveries].[DeliveryID] Between #" & Me.StartDate & # AND #" & Me.EndDate & "#"
DoCmd.RunCommand acCmdApplyFilterSort
End Sub
would someone please point out what the issue is? Thank you.
Upvotes: 1
Views: 48
Reputation: 55856
Use the correct syntax:
Private Sub btnDateRange_Click()
Me.Filter = "[tblDeliveries].[DeliveryID] Between #" & Format(Me.StartDate, "yyyy\/mm\/dd") & "# AND #" & Format(Me.EndDate, "yyyy\/mm\/dd") & "#"
Me.FilterOn = True
End Sub
Upvotes: 1