使用OpenArgs在表单之间传递值 [英] Passing Values Between Forms using OpenArgs

查看:139
本文介绍了使用OpenArgs在表单之间传递值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

*****编辑

因此,我有一个标题为"NewInvoice"的表格.此表单将编辑一个包含以下内容的发票"表;发票编号,客户,订单日期.在此表单中,我有一个按钮,用于打开名为"InvoiceItem"的子表单.这将编辑一个具有相同名称的表,其中包含发票编号,项目代码,尺寸等.

So I have a form titled "NewInvoice". This form edits a table "Invoice" which contains the following; Invoice Number, Customer, Order Date. In this form I have a button which opens a subform titled "InvoiceItem". This edits a table with the same name that contains Invoice Number, Item Code, Dimensions, Etc.

现在,我的按钮具有如下的事件过程.

Now currently, my button has an event procedure as follows.

私人子CreateInvoiceItem_Click()

Private Sub CreateInvoiceItem_Click()

DoCmd.OpenForm"InvoiceItem",OpenArgs:="InvoiceNumber"

DoCmd.OpenForm "InvoiceItem", OpenArgs:="InvoiceNumber"

结束子

(我使用按钮并在单独的窗口中打开表单的原因是因为我在子表单中层叠了多个组合框,当将子表单插入父表单时这些组合框被破坏了)

(The reason I am using a button and opening the form in a separate window is because I have cascading combo boxes in the sub form that become broken when I insert the sub form into the parent form)

现在我遇到麻烦的地方是设置Form Load命令.我想发生的是,当单击按钮时,在父"表单中填写的InvoiceNumber会自动填写子表单.

Now where I am having trouble is setting the Form Load command. What I would like to occur is that the InvoiceNumber which is filled out in the Parent form auto fills in the sub form when the button is clicked.

私人子Form_Load()

Private Sub Form_Load()

****所需代码****

**** NEEDED CODE****

结束子

推荐答案

我发现最好的方法是在要打开的表单中添加Public子对象,然后将所需的任何参数传递给此函数当您打开表单时.因此,要做您想做的事情,将这样的功能添加到您要打开的表单中;

I find that the best way to do this is to add a Public sub to the form that you're opening and then pass whatever parameters you need to this function when you open the form. So to do what you're looking to do add a function like this to the form that you're opening;

Public Sub SetUpForm(InvoiceNumber as Long)

    txtInvoiceNumber.Value = InvoiceNumber

End Sub

其中txtInvoiceNumber是要在其中输入值的表单上的控件.

Where txtInvoiceNumber is the control on the form that you want to put the value into.

然后点击按钮

DoCmd.OpenForm "InvoiceItem"
Forms!InvoiceItem.SetUpForm InvoiceNumber

这会将发票编号的值传递给您要打开的表单上的控件.这还为您提供了更大的控制过程灵活性,因为您可以将多个参数传递给子对象,并且在子对象中您可以执行任意数量的任务.

This will pass your value for the invoice number to the control on the form that you're opening. This also gives you a lot more flexibility to control the process because you can pass more than one parameter to the sub and in the sub you can perform any number of tasks.

这篇关于使用OpenArgs在表单之间传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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