title: How to keep focus after requery in MS Access?
body: <p>I am using the following code in VBA to keep focus on a certain recordset even after requery :</p>
  
  <pre><code>With Forms!frmMain!frmMainSub
          strControlName = .Form.ActiveControl.Name
          lngCurrentPos = .Form.Recordset.AbsolutePosition
          .Requery
          .Form.Recordset.AbsolutePosition = lngCurrentPos
          .Form.Controls(strControlName).SetFocus
      End With
  </code></pre>
  
  <p>The problem with this code is that the subform is in datasheet view and is usually sorted by a field. Since the code above records the absolute position on dynaset- or snapshot-type Recordset object, it cannot keep track of the sorted datasheet.</p>
  
  <p>Is there a better way to keep focus on a specific field after the form is requeired?</p>
  
  <p>Edit:</p>
  
  <p>This question is not a duplicate because there are answers about keeping the focus from the same form. The problem is that I am in a different form and also I want to preserve focus even when filter is applied to one of the fields.</p>