访问:在第二种形式中创建后,如何在一种形式中显示新记录 [英] Access: How can I display a new record in one form after creating in a second form

查看:51
本文介绍了访问:在第二种形式中创建后,如何在一种形式中显示新记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Access 2007:我有一个显示100条记录的表单.我还有第二种形式用于编辑或创建新记录.添加新记录后返回第一个表单时,我会执行激活:Me.Requery",以便将新记录添加到列表中,但是我希望它与新记录中的记录选择器一起显示在屏幕上.有没有办法做到这一点?我假设我将ID保存在全局变量中,但是不确定下一步该怎么做.谢谢.

Access 2007: I have one form with 100s of records displayed. I have a second form for editing or creating new records. When I return to the first form after adding a new record, I do On Activate: Me.Requery so the new record is added to the list, but I would like it to display on the screen with the record selector on the new record. Is there a way to do this? I am assuming that I save the ID in a global variable, but not sure what to do next. Thanks.

响应: 谢谢//t.您的回答使我朝着正确的方向前进.我将发布我的解决方案,我认为这更多是一种解决方法.必须有一个更好的解决方案,但这似乎行得通.

RESPONSE: Thanks //t. Your answer got me going in the right direction. I will post my solution, which I think is more of a work-around. There has to be a better solution, but this seems to work.

表格1(列表)->表格2(编辑/新建)并创建新记录.

Form 1 (list) -> Form 2 (edit/new) and create new record.

Private Sub Form_Current ()
  glngID = Me.ID.Value
End Sub

Private Sub Form_Close
  gstrLastForm = "Form2"
End Sub

当我关闭Form 2时,Form 1处于活动状态.

When I close Form 2, Form 1 is active.

Private lngSelectedRecord as Long

Private Sub Form_Activate()
  Me.Requery
  FindSelectedRecord
  If gstrLastForm = "Form2" Then
    DoCmd.GoToRecord acDataForm, "Form1", acGoTo, lngSelectedRecord
  End If 
End Sub

Private Sub FindSelectedRecord()
  ...
  Open recordset, move through records, increment counter, exit when ID found
  ...
  lngSelectedRecord = intCounter
  ...
End Sub 

推荐答案

使用弹出窗口中的on_close方法转到插入的记录, 像这样:

Use the on_close-method in your popup window to go to the inserted record, something like:

private sub on_close()
  'maby first check we're not undoing..
  docmd.gotoRecord yourform,yournewid
  me.close

(目前在osx上,但希望您能理解...)

(on osx currently, but I hope you get the concept...)

这篇关于访问:在第二种形式中创建后,如何在一种形式中显示新记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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