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

查看:504
本文介绍了在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是一个读/写属性,在最后一行我仍收到错误消息"Invalid use of property".

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天全站免登陆