title: How to apply filter on a sub-form by pressing a button based on date values from two textboxes
body: <p>I am trying to built a VBA code that somehow apply a filter that only shows records where the field [Date] value comes between from &amp; To dates(User input). below is my Form View.</p>
  
  <p><a href="https://i.stack.imgur.com/BiGyu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BiGyu.jpg" alt="Form View"></a></p>
  
  <p>Object Names are as below</p>
  
  <p>Set Range Button = btnSetRange, From TextBox = txtFromDate; To TextBox = txtToDate; Subform Name= ShipmentHistoryDataSheet; Subform-Source Object = Forms![Shipment-History subform]. Shipment-History subform Record Source is a select query from Table "Shipment-History".</p>
  
  <p>I have tried to write the code by myself but didn't worked out well as I'm not an expert in access or coding. below is the code that i wrote, But not working as expected:P</p>
  
  <pre><code>Private Sub btnSetRange_Click()
  
          Dim subform2 As Form
  
          Set subform2 = Me!ShipmentHistoryDataSheet.Form
  
          subform2.Filter = "[Date]&gt;" &amp; Me.txtFromDate And "[Date]&lt;" &amp; Me.txtToDate
  
          subform2.FilterOn = True
          subform2.Requery
  
  End Sub
  </code></pre>
  
  <p>Can anybody help?</p>