OpenArgs不能将值传递给下一个表单吗

OpenArgs不能将值传递给下一个表单吗

本文介绍了MS Access 2007-OpenArgs不能将值传递给下一个表单吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我使用一种形式将ID值从一种形式传递给另一种形式

So I pass the ID value from one form to the next using

Docmd.OpenForm "SecondForm",,,,,, MainID
Docmd.Close AcForm, "FirstForm", acSaveYes

然后检查第二个表单"的load事件上的值:

and then I check the value on the Second Form's load event:

MainID = val(Me.OpenArgs)

当我调试和逐步调试时,将鼠标悬停在它上面,可以看到它包含一个值

and when I debug and step through I hover over this and can see it contains a value

然后我在第二个窗体上有一个按钮单击事件,该事件应该重复该过程,但是当我运行以下命令时

Then I have a button click event on the Second Form that is supposed to repeat the process, but when I run the following

Dim rs as DAO.Recordset
Dim dbs as DAO.Database
Set dbs = CurrentDB

Set MyRS = dbs.OpenRecordset("tblMain")

If MyRS!MainID = MainID THen

之后是一些rs.edit等内容...例程甚至还没走那么远.一旦执行相同的调试和悬停,此处的值为空.我是否缺少某些东西,因为我可以看到表格加载事件中的值,但是一旦我尝试在其他操作中使用它,那就是MIA

after that its some rs.edit, etc stuff....the routine is not even making it that far. Once I do the same debug and hover, the value here is empty. Is there something I am missing because I can see the value on the forms load event, but once i try to use it in another action it is MIA

谢谢贾斯汀

推荐答案

类似的声音可能是范围问题. MainID在哪里声明?

Sounds like this could be a scope problem. Where is MainID declared?

如果您在表单打开"过程中声明它,则该过程完成后就消失了.

If you declare it within your Form Open procedure, it's gone once that procedure finishes.

考虑更改按钮的点击事件过程.

Consider changing your button's click event procedure.

If MyRS!MainID = Val(Me.OpenArgs) Then

在表单加载后,OpenArgs不会消失".我不明白为什么您需要将OpenArgs存储到您的MainID变量中.您可以在使用MainID变量的地方使用Val(Me.OpenArgs).

OpenArgs doesn't "go away" after Form Load. I don't see why you need to store OpenArgs to your MainID variable. You could use Val(Me.OpenArgs) where you were using the MainID variable.

或者,您可以将MainID设置为模块级别的变量,以便所有表单过程都可以使用它.

Alternatively, you could make MainID a module level variable so it would be available to all your form's procedures.

更新:是否有可能在不向表单提供OpenArgs值的情况下打开表单?如果是这样,Val(Me.OpenArgs)将返回0.这是否是应用程序逻辑中的错误条件?当未提供OpenArgs值时,命令按钮是否应该可单击"(启用)?

Update: Is there any situation where you might open the form without feeding it a value for OpenArgs? If so, Val(Me.OpenArgs) will return 0. Will that be an error condition in your application's logic? Should your command button be "clickable" (enabled) when an OpenArgs value has not been supplied?

这篇关于MS Access 2007-OpenArgs不能将值传递给下一个表单吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 15:07