关闭弹出窗体时,将主窗体保留在同一记录中 [英] when close a Pop-up form, keep main form on same record

查看:66
本文介绍了关闭弹出窗体时,将主窗体保留在同一记录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我知道我以前见过这个问题的答案,但我似乎无法再找到它。搜索了几个小时后,我决定重新发帖,希望有人可以提供建议和/或发送给我现有的帖子...


我有一个主要的具有多个子表单的表单。在每个子表单上都有一个按钮,用于打开弹出窗体,用户可以在其中输入数据。但是,当我关闭弹出窗体时,mainform /子窗体跳转到第一个记录而不是保持在同一记录中。我知道我应该为记录集克隆添加书签,但我遇到了代码问题,因为我介于两种不同的形式之间。我想从弹出窗体中保存ID,然后在主窗体中找到具有该ID的记录。我有一个关闭弹出窗口的按钮,我想将此代码添加到On_Click事件中,不是吗?


我正在尝试学习VBA,但是我很慢,所以如果有人可以推荐合适的代码,我会非常感激!


非常感谢,

Bridget

Hello,
I know I''ve seen an answer to this question before, but I cannot seem to find it again. After searching for a few hours, I''ve decided to re-post in hopes someone can give advice and/or send me to an existing thread...

I have a main form with a number of subforms. On each subform there is a button that opens a Pop-up form where users can enter data. When I close the Pop-up form, however, the mainform/subform jump to the first record rather than staying at the same record. I know I should bookmark a recordset clone, but I am having trouble with the code because I''m going between two different forms. I want to save the ID from the Pop-up form and then find the record with that ID in the main form. I have a button that closes the Pop-up and figure I should add this code to the On_Click event, no?

I am trying to learn VBA, but am very slow, so if someone can recommend appropriate code, I would be very appreciative!

Thanks so much,
Bridget

推荐答案


我有一个关闭弹出窗口的按钮,我想将此代码添加到On_Click事件中,不是吗?
I have a button that closes the Pop-up and figure I should add this code to the On_Click event, no?





您可以尝试的一件事是您的主表单上的公共变量,然后当您关闭弹出窗体时,您可以设置变量等于弹出窗口中的ID。

然后你安排这样,当主窗体刷新时,它使用公共变量的内容移动到正确的记录。


或其他可能更好的可能性是在mainform上添加一个公共参数化子例程。这样,在按钮的on click事件中,你调用public sub传递参数中的id。


这有帮助吗?

Yes
One thing you could try is a public variable on your main form and then as you close the popup form you could set that variable to equal the ID from the popup.
Then you arrange so that when the mainform gets refreshed it uses the contents of the public variable to move to the correct record.

or another, probably better, possibility would be to add a public parameterised subroutine on your mainform. That way, in the on click event of the button you call that public sub passing the id in the parameter.

Does that help?


您好Delerna,

感谢您的回复!

是的,这些选项是有道理的。但是我对代码不是很了解。 (相对较新的Access)。能够建议一些代码来实现这个公共变量/ sub?

Bridget


Hello Delerna,
Thank you for your reply!
Yes these options make sense. I am not very good with code however. (relatively new to Access). Would be able to suggest some code to implement this public variable / sub?

Bridget





您可以尝试的一件事是主窗体上的公共变量,然后当您关闭弹出窗体时,您可以将该变量设置为等于弹出窗口中的ID。

然后你安排好这样当主要形态被刷新时,它使用公共变量的内容移动到正确的记录。


或另一个,可能更好,可能是在mainform上添加一个public parameterised子例程。这样,在按钮的on click事件中,你调用public sub传递参数中的id。


这有帮助吗?
Yes
One thing you could try is a public variable on your main form and then as you close the popup form you could set that variable to equal the ID from the popup.
Then you arrange so that when the mainform gets refreshed it uses the contents of the public variable to move to the correct record.

or another, probably better, possibility would be to add a public parameterised subroutine on your mainform. That way, in the on click event of the button you call that public sub passing the id in the parameter.

Does that help?


yes 这里是一个非常类似于你的问题。

虽然你需要使用GotoRecord或类似的东西。


如果你有麻烦,如果你有麻烦回到这里,你已经尝试了什么以及你遇到了什么问题,我或其他人都会很乐意提供帮助。


PS Don''忘记帮助菜单,那里有一些很棒的东西用于学习基础知识
yes here is a question very similar to yours.
Although you are going to need to use GotoRecord or something like that.

Have a go and if you have trouble post back here with what you have tried and what problem you are having and either I or someone else will be glad to assist.

PS Don''t forget the help menu, theres some great stuff in there for learning the basics


这篇关于关闭弹出窗体时,将主窗体保留在同一记录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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