MS访问:使用另一个表单中的命令按钮输入表单中的特定文本 [英] MS Access: Enter a specific text in a form using command button from another form

查看:217
本文介绍了MS访问:使用另一个表单中的命令按钮输入表单中的特定文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要求您在MS Access中的以下问题的帮助。

I would like to ask for your help on the following issue in MS Access.

我创建了一个表单CustomerListF,用每个客户端的命令按钮填充。对于每个按钮,我创建了以下代码:

I had created a form "CustomerListF", filled with command buttons for each client. For each button, I had created the following code:

Private Sub cmd_outlets_ABC_Click()
DoCmd.OpenForm "OrderFormF"
Forms!OrderFormF!Outlets = "ABC"
End Sub 

将打开另一个表单OrderFormF,并在名为Outlets的文本框中输入ABC。但是,我意识到第二行代码(Forms!OrderFormF!Outlets =ABC)将始终在我的子表单中创建一个幻影记录,它位于OrderFormF中,并且此记录将传递到其他客户端的表单。该幻像记录通常在单击命令按钮两次(双击或后续点击)时创建。这是一个头痛,当记录开始转移。

The button would then open another form "OrderFormF" and enter "ABC" in the textbox named "Outlets". However, I realized the second line of code (Forms!OrderFormF!Outlets = "ABC") would always create a phantom record in my subform, which is located in "OrderFormF", and this record would travel to other clients' forms. This phantom record is usually created when the commandbutton is clicked twice (double clicks or subsequent clicks). It is a headache when the record starts to shift around.

请在这里输入图片说明

我想征求您对vba代码的意见,以编辑第二行代码。

I would like to seek your advice for vba code to edit the second line of code.

谢谢。

推荐答案

打开形式不好。 OrderFormF初始化和你的代码的第二行赋值给字段可能会以不同的顺序执行,它们是不同步的。
为了避免这种情况,你应该通过另一种方式将参数传递给OrderFormF。我建议使用 OpenArgs 参数:

This approach for filling the field in opened form is not good. OrderFormF initialization and second line of your code with assigning value to the field may be executed in different sequence, they are not synchronized. In order to avoid this, you should pass the argument to OrderFormF by another way. I would recommend to use OpenArgs parameter:

DoCmd.OpenForm "OrderFormF",,,,,,"ABC"

然后在OrderFormF的Load事件中文本框:

And then in Load event of OrderFormF assign the value to textbox:

Me.Outlets = Me.OpenArgs

在这种情况下,如果form为空,ABC值将被分配到窗体中的第一行或新记录。在分配之前,如果您需要将值分配给第一行,则可以选择行。此外,这种方式将保护您免受双击按钮,加载事件只执行一次在第一个窗体打开

In this case the "ABC" value will be assigned to first row in the form or to new record, if form is empty. Before assigning you can select the row if you need to assign value not to the first row. Also this way will protect you against double click on button, Load event executed only once during first form opening

这篇关于MS访问:使用另一个表单中的命令按钮输入表单中的特定文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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