sambob_628
sambob_628

Reputation: 133

DoCmdApplyFilter does not recognise text input field

I have a form in ms access I want to filter between two dates updated on the click of a button. The field I want to filter is called Date

The dates to be filtered by are entered though a couple of a textboxs in short date format called TxtDtStrt and TxtDtEnd the button is called NCRDateFilter

Using the NCRDateFilter button event procedure 'On Click' and the below code I would expect the form the be filtered by date range between TxtDtStrt and TxtDtEnd values

Private Sub NCRDateFilter_Click()

    DoCmd.ApplyFilter "", "[Date] Between [TxtDtStrt] And [TxtDtEnd]", ""

End Sub

But it doesn't use the TxtDtStrt/TxtDtEnd values, instead shows popups asking for the TxtDtStrt and then another for the TxtDtEnd value....

Upvotes: 1

Views: 31

Answers (1)

Gustav
Gustav

Reputation: 55881

Try with static values (see Docs example):

DoCmd.ApplyFilter , "[Date] Between #" & Format([TxtDtStrt], "yyyy\/mm\/dd") & "# And #" & Format([TxtDtEnd], "yyyy\/mm\/dd") & "#"

Upvotes: 1

Related Questions