Access表单中,重新查询后如何返回上一条记录 [英] In an Access form, how to return to previous record after requery

查看:30
本文介绍了Access表单中,重新查询后如何返回上一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该很容易.此表单由 [Dismissed] = "N" 过滤.当用户单击Dismiss"按钮时,[Dismissed] 字段变为Y".重新查询后,表单应返回到用户之前所在的同一行.

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 requery, the form should then return to the same row where the user was previously at.

Private Sub DismissButton_Click()
   Me!Dismissed = "Y"
   MsgBox "Dismissed!", vbOKOnly
   Dim GoBackToThisRecord As Integer
   GobacktothisRecord = Me.CurrentRecord
   Me.Requery
   Set Me.CurrentRecord=GoBackToThisRecord
End Sub

然而,即使内置帮助文件说 CurrentRecord 是一个读/写属性,我还是在最后一行收到属性的无效使用"错误消息.

However, even though the built-in help files say that CurrentRecord is a read/write property, I get an "Invalid use of property" error message on this last line.

设置 [Dismiss]="Y" 并重新查询表单后,如何让用户回到他/她之前在表单中的位置?

After setting the [Dismiss]="Y", and requerying the form, how do I get the user back to his/her previous location in the form?

推荐答案

如果表单被过滤到编辑的记录不再匹配的值,我不明白你的解决方案如何工作——如果你被过滤了[Dismissed] = "N" 然后将当前记录的 Dismissed 字段更改为 Y 应该会导致重新查询的表单排除您刚刚更新的记录.

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.

除此之外,我永远不会像你那样做,因为 Me.CurrentRecord 返回一个代表记录中位置的数字.由于重新查询会导致记录数发生变化(例如,其他人编辑或添加或删除记录导致其被包含/排除在表单的记录集中)以及所寻求记录的位置发生变化,我会使用代替PK.

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.

这篇关于Access表单中,重新查询后如何返回上一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆