使用字符串调用表单的方法 [英] Calling form's methods using a string

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

问题描述

我知道你可以通过这样的方式从另一个

表单中调用一个方法


表格(MyForm) .MyFunction(12,34)


但是,您必须知道MyForm有一个名为

MyFunction的函数。你可以像你一样为函数名指定一个字符串

可以使用表单名吗?我可以做一些像


表格(MyForm)。MyFunction


并且仍然提供一些参数给功能不知怎么样?


谢谢,

Dave

I know that you can call the method of one from from inside another
form by doing something like this

Forms("MyForm").MyFunction(12, 34)

However, you have to know that MyForm has a function called
MyFunction. Can you specify a string for the function name like you
can with the form name? That is can I do something like

Forms("MyForm")."MyFunction"

and still supply some arguments to the funciton somehow?

Thanks,
Dave

推荐答案

4月10日2004年14:38:46 -0700, he******@aol.com (headware)写道:


在帮助文件中查看Eval。

-Tom。
On 10 Apr 2004 14:38:46 -0700, he******@aol.com (headware) wrote:

Check out Eval in the help file.
-Tom.
我知道你可以调用方法表格(MyForm)表格(MyForm)。来自内部的一个表格(MyForm)。我的功能(12,34)

然而,你有要知道MyForm有一个名为
MyFunction的函数。你可以为表单名称指定函数名称的字符串吗?那我可以做一些类似

形式(MyForm)。MyFunction

并且仍以某种方式向函数提供一些参数吗?
<谢谢,
戴夫
I know that you can call the method of one from from inside another
form by doing something like this

Forms("MyForm").MyFunction(12, 34)

However, you have to know that MyForm has a function called
MyFunction. Can you specify a string for the function name like you
can with the form name? That is can I do something like

Forms("MyForm")."MyFunction"

and still supply some arguments to the funciton somehow?

Thanks,
Dave






汤姆,


我调查了Eval功能,但要么我不太了解

关于如何使用它,或者它不会做我需要它。我是

试图创建一个函数调用,如


表格(MyForm)。MyFunction#4/12/2004#


将以另一种形式调用子程序并将其传递给日期

值。问题是Eval函数不断报告语法

错误。我尝试通过OpenArgs参数将表单名称和函数名称传递到

调用表单中,解析出来,并从该表单调用

函数。 />

调用表单包含以下代码:

DoCmd.OpenForm" frmCaller",OpenArgs:= Me.Name& " ;; MyCallback"

调用回调函数(frmCaller)的表单使用OpenArgs变量中的数据执行




Dim args As String

Dim sepIdx As Integer

Dim formName,callback As String


args = Me.OpenArgs''包含要调用的表单名称和函数名称

sepIdx = InStr(args," ;;")

formName = Mid(args,1 ,sepIdx - 1)''解析表单名称

callback = Mid(args,sepIdx + 1,Len(args) - sepIdx)''解析

回调


Eval" Forms(""& formName&""")。" &安培;回调& " #1/1/2004#"


我收到一个消息框,上面写着你输入的表达式包含

语法无效。我正在查看关于Eval

函数的文档,它似乎表明调用的例程应该返回一个值。所以我让回调例程返回一个毫无意义的

值。执行该代码只会导致Access崩溃。回调

函数以另一种形式设置某个控件的值。可能

是问题吗?我很难过。


Dave


Tom van Stiphout< to ***** @ no.spam.cox.net> ;在消息新闻中写道:< lc ******************************** @ 4ax.com>。 ..
Tom,

I looked into the Eval function but either I don''t understand enough
about how to use it or it''s not going to do what I need it to. I''m
attempting to create a function call like

Forms("MyForm").MyFunction #4/12/2004#

which will call a sub-routine in another form and pass it a date
value. The problem is that the Eval function keeps reporting a syntax
error. I try to pass in the form name and function name into the
calling form through the OpenArgs parameter, parse them out, and call
the function from that form.

The calling form contains the following code:

DoCmd.OpenForm "frmCaller", OpenArgs:=Me.Name & ";MyCallback"

The form that invokes the callback function (frmCaller) does the
following with the data in the OpenArgs variable

Dim args As String
Dim sepIdx As Integer
Dim formName, callback As String

args = Me.OpenArgs ''contains the form name and function name to call
sepIdx = InStr(args, ";")
formName = Mid(args, 1, sepIdx - 1) ''parse out form name
callback = Mid(args, sepIdx + 1, Len(args) - sepIdx) ''parse out
callback

Eval "Forms(""" & formName & """)." & callback & " #1/1/2004#"

I get a message box saying "The expression you entered contains
invalid syntax". I was looking at the documentation on the Eval
function and it seemed to indicate that the routine called should
return a value. So I made the callback routine return a meaningless
value. Executing that code just caused Access to crash. The callback
function sets the value of a certain control in another form. Could
that be the problem? I''m stumped.

Dave

Tom van Stiphout <to*****@no.spam.cox.net> wrote in message news:<lc********************************@4ax.com>. ..
2004年4月10日14:38:46 -0700,他****** @ aol.com (headware)写道:

在帮助文件中查看Eval。
-Tom。
On 10 Apr 2004 14:38:46 -0700, he******@aol.com (headware) wrote:

Check out Eval in the help file.
-Tom.
我知道你可以通过这样的方式从另一个
形式调用一个方法

形式(MyForm)。MyFunction(12,34)
但是,您必须知道MyForm有一个名为
MyFunction的函数。你可以为表单名称指定函数名称的字符串吗?那我可以做一些类似

形式(MyForm)。MyFunction

并且仍以某种方式向函数提供一些参数吗?
<谢谢,
Dave
I know that you can call the method of one from from inside another
form by doing something like this

Forms("MyForm").MyFunction(12, 34)

However, you have to know that MyForm has a function called
MyFunction. Can you specify a string for the function name like you
can with the form name? That is can I do something like

Forms("MyForm")."MyFunction"

and still supply some arguments to the funciton somehow?

Thanks,
Dave



2004年4月10日下午05:38,他****** @ aol.com (头饰)写在

新闻:e3 ****** ********************@posting.google.c om:
On Apr 10 2004, 05:38 pm, he******@aol.com (headware) wrote in
news:e3**************************@posting.google.c om:
我知道你可以调用一个方法来自内部的另一种形式,通过做这样的事情

形式(MyForm)。MyFunction(12,34)

然而,你必须知道MyForm有一个名为
MyFunction的函数。你可以为表单名称指定函数名称的字符串吗?那我可以做一些类似

形式(MyForm)。MyFunction

并且仍以某种方式向函数提供一些参数吗?
I know that you can call the method of one from from inside another
form by doing something like this

Forms("MyForm").MyFunction(12, 34)

However, you have to know that MyForm has a function called
MyFunction. Can you specify a string for the function name like you
can with the form name? That is can I do something like

Forms("MyForm")."MyFunction"

and still supply some arguments to the funciton somehow?




如果你使用的是Access 2002或2003,你可以使用CallByName函数(不是

总是 - 从命令栏调用时不起作用)。否则,Eval可能会工作,但要注意一个长期存在的错误,导致形式代码在

中以这种方式执行多次。我会说完整的东西不值得

早期版本的Access的努力。


-

删除a 9通过电子邮件回复



If you are using Access 2002 or 2003, you can use CallByName function (not
always - doesn''t work when called from commandbars). Otherwise, Eval might
work, but beware of a long standing bug that causes form code called in
this way to execute multiple times. I''d say the whole thing is not worth
the effort in earlier versions of Access.

--
remove a 9 to reply by email


这篇关于使用字符串调用表单的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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