避免陷阱 [英] A trap to avoid

查看:73
本文介绍了避免陷阱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于从http />
代码中读取Access 2000和2002中的计算控件的值,最多证明是不可靠的,因为我想避免运行

单独的查询来计算总和子窗体记录,因为如果有超过接口或用户访问

的表格,他们可以给出

不一致的结果,我编写代码来循环子表单将RecordsetClone计算为

计算总值。


这种方法运行良好,直到我转移到没有相关的主记录

子表单中的记录。移动到该记录后,子表单从那时起返回

一个空的记录集克隆,即使我移回到具有相关记录的父级

行后,它们出现在子窗体。


我想出的解决方法是编写一个函数,它接受一个表单作为

a参数并返回表单的'RecordsetClone if该表格有记录

count> 1如果当前记录是新的,则不计算新记录。如果

表单'的记录数为零,则该函数返回Nothing,而不是
尝试访问表单的RecordsetClone。这解决了这个问题。


想到你们都想知道。


- Steve Jorgensen

----

我会给你写一个较短的程序,

但是我没有时间。

Since reading values from calculated controls in Access 2000 and 2002 from
code has proven unrliable at best, and since I like to avoid running
separate queries to calculate sums of subform records since they can give
inconsistent results if there''s more than on interface or user with access
to the table, I wrote code to loop through a subform''s RecordsetClone to
calculate aggregate values.

This approach worked fine until I moved to a master record with no related
records in the subform. After moving to that record, the subform returned
an empty recordset clone from then on even after I moved back to a parent
row with related records, and they appeared in the subform.

The work-around I came up with was to write a function that takes a form as
a parameter and returns the form''s RecordsetClone if the form has a record
count > 1 not counting the new record if the current record is new. If the
form''s record count is zero, the function returns Nothing, and does not
attempt to access the form''s RecordsetClone. This solved the problem.

Just thought y''all might want to know.

- Steve Jorgensen

----
I would have written you a shorter program,
but I didn''t have the time.

推荐答案

史蒂夫,感谢您发表您的提示赞赏。


仍然让我担心的一点是,如果子窗体被过滤。


-

Allen Browne - 微软MVP。西澳大利亚州珀斯。

访问用户提示 - http:// allenbrowne.com/tips.html


" Steve Jorgensen" <无**** @ nospam.nospam>在留言中写道

news:4a ******************************** @ 4ax.com ...
Steve, thanks for posting your tips appreciated.

The bit that still worries me about this is if the subform is filtered.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html

"Steve Jorgensen" <no****@nospam.nospam> wrote in message
news:4a********************************@4ax.com...
由于从Access 2000和2002中的计算控件中读取代码的代码最多已证明是不可靠的,因为我希望避免运行单独的查询来计算总和子窗体记录,因为他们可以提供不一致的结果,如果有更多的接口或用户访问表,我写代码循环子窗体的RecordsetClone到
计算总值。

这种方法运行良好,直到我转到主记录,子表单中没有相关的
记录。移动到该记录后,子表单从那时起返回了一个空记录集克隆,即使在我移回到具有相关记录的父行后,它们也出现在子表单中。
形式作为参数,如果表单有记录,则返回表单'RecordsetClone>> 1如果当前记录是新的,则不计算新记录。如果
格式的记录计数为零,则该函数返回Nothing,并且不会尝试访问表单的RecordsetClone。这解决了这个问题。

只是想你们都想知道。

- 史蒂夫乔根森

---- 我本来会给你写一个较短的程序,
但是我没有时间。
Since reading values from calculated controls in Access 2000 and 2002 from
code has proven unrliable at best, and since I like to avoid running
separate queries to calculate sums of subform records since they can give
inconsistent results if there''s more than on interface or user with access
to the table, I wrote code to loop through a subform''s RecordsetClone to
calculate aggregate values.

This approach worked fine until I moved to a master record with no related
records in the subform. After moving to that record, the subform returned
an empty recordset clone from then on even after I moved back to a parent
row with related records, and they appeared in the subform.

The work-around I came up with was to write a function that takes a form as a parameter and returns the form''s RecordsetClone if the form has a record
count > 1 not counting the new record if the current record is new. If the form''s record count is zero, the function returns Nothing, and does not
attempt to access the form''s RecordsetClone. This solved the problem.

Just thought y''all might want to know.

- Steve Jorgensen

----
I would have written you a shorter program,
but I didn''t have the time.



2003年9月5日,09:下午17点,Steve Jorgensen< no **** @ nospam.nospam>在新闻中写道

:4a ******************************** @ 4ax.com:
On Sep 05 2003, 09:17 pm, Steve Jorgensen <no****@nospam.nospam> wrote
in news:4a********************************@4ax.com:
由于从代码中读取Access 2000和2002中的计算控件的值已经证明最多是不可靠的
Since reading values from calculated controls in Access 2000 and 2002
from code has proven unrliable at best




史蒂夫,


也许最近我已经讨论了这个问题,但我只是错过了,但是你可以稍微详细说明吗?它与Access 97的工作方式有什么不同吗?


-

(删除9以通过电子邮件回复)



Steve,

Maybe this has been covered recently and I just missed it, but can you
elaborate a bit? Is there a difference from the way it works in Access 97?

--
(remove a 9 to reply by email)


Steve Jorgensen写道:
Steve Jorgensen wrote:
因为从代码中读取Access 2000和2002中的计算控件的值已证明最多是不可靠的,因为我喜欢避免
运行单独的查询来计算子表单记录的总和,因为如果有更多的接口
或者用户可以访问表,他们可以给出不一致的结果,我编写代码来循环一个
子窗体的RecordsetClone来计算聚合值。

这种方法工作正常,直到我转移到主记录,子窗体中没有
相关记录。移动到该记录后,
子窗体从那时起返回一个空的记录集克隆,即使在我移回到具有相关记录的父行之后,它们也出现在子窗体中。

我想出的解决方法是编写一个以
形式作为参数的函数,如果表格
有记录计数,则返回表单'RecordsetClone> ; 1如果当前
记录是新的,则不计算新记录。如果表单的记录数为零,则函数
返回Nothing,并且不会尝试访问表单'
RecordsetClone。这解决了这个问题。

只是想你们都想知道。


是的,好的史蒂夫,或者我应该说''arrrghh'' - 另一种方式我的应用可能会因为我有类似的代码在某处运行而打破b $ b。 ..

- 史蒂夫乔根森

----
我会给你写一个较短的节目,
但我没有'没时间。
Since reading values from calculated controls in Access 2000 and 2002
from code has proven unrliable at best, and since I like to avoid
running separate queries to calculate sums of subform records since
they can give inconsistent results if there''s more than on interface
or user with access to the table, I wrote code to loop through a
subform''s RecordsetClone to calculate aggregate values.

This approach worked fine until I moved to a master record with no
related records in the subform. After moving to that record, the
subform returned an empty recordset clone from then on even after I
moved back to a parent row with related records, and they appeared in
the subform.

The work-around I came up with was to write a function that takes a
form as a parameter and returns the form''s RecordsetClone if the form
has a record count > 1 not counting the new record if the current
record is new. If the form''s record count is zero, the function
returns Nothing, and does not attempt to access the form''s
RecordsetClone. This solved the problem.

Just thought y''all might want to know.
Yeah, nice one Steve, or should I say ''arrrghh'' - another way my app might
break because i have similar code running somewhere...


- Steve Jorgensen

----
I would have written you a shorter program,
but I didn''t have the time.






这篇关于避免陷阱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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