In an Access form, how to return to previous record after requery

后端 未结 4 1767
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-21 14:49

This should be an easy one. This form is filtered by [Dismissed] = \"N\". When the user clicks the \"Dismiss\" button, the [Dismissed] field changes to \"Y\". After the r

4条回答
  •  -上瘾入骨i
    2020-12-21 15:09

    I don't understand how your solution can work if the form is filtered to a value that the edited record no longer matches -- if you're filtered on [Dismissed] = "N" then changing the current record's Dismissed field to Y should cause the requeried form to exclude the record you've just updated.

    That aside, I would never do it the way you've done it, as Me.CurrentRecord returns a number representing the position in the record. Since a requery can cause the number of records to change (e.g., somebody else edits or adds or deletes a record causing it to be included/excluded from the form's recordset) and the position of the sought-for record to change, I would use the PK instead.

      Dim lngPK as Long
    
      lngPK = Me!MyPKID
      Me.Requery
      With Me.RecordsetClone
        .FindFirst "[MyPKID]=" & lngPK
        If Not .NoMatch Then
           If Me.Dirty Then
              Me.Dirty = False
           End If
           Me.Bookmark = .Bookmark
        End If
      End With
    

    That won't deal with the filter issue, but I leave that aside, since it didn't seem to be the issue that I thought it would be from the description of the original problem.

提交回复
热议问题