For Each循环对象声明问题。 [英] For Each loop object declaration issues.

查看:123
本文介绍了For Each循环对象声明问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我是Access的新手,想知道是否有人可以帮我解决我的VBA语法错误。


我有一个表,3个字段应该更新第4个字段,但引用3个其他表 - 每个表链接到3个字段之一。这部分似乎工作正常,但是我希望它能够为表格中的每个记录执行此操作,目前它只针对第一个记录执行。


我尝试过使用For Each声明,但这显然对这种类型的对象无效。


关于如何以不同方式声明事物的任何想法?


谢谢


Zoe


我的代码如下:


Hi,

I am very new to Access and wondered if anyone could help with a syntax error I have with my VBA.

I have a table, and 3 fields which should update a 4th field, but referencing 3 other tables - each linked to one of the 3 fields. This section seems to work fine, however I want it to do it for every record in the table and currently it only does it for the first one.

I have tried using the For Each statement, but this is apparently invalid for "this type of object".

Any ideas of how I can declare things differently?

Thanks

Zoe

My code is as follows:


展开 | 选择 | Wrap | 行号

推荐答案

而不是For Each Statemen t,尝试使用EOF属性循环遍历记录集。

Instead of a For Each statement, try looping through the recordset using the EOF property..

展开 | 选择 | Wrap | 行号


拥有上述代码导致结束,没有结束编译错误。所以我把它换了一圈(如下图所示),现在我得到了无效或不合格的参考。突出显示.EOF。

Having the code as stated above resulted in a "end with, without with" compile error. So I''ve swapped it round (as shown below) and now I get "invalid or unqualified reference" highlighting the .EOF.

展开 | 选择 | Wrap | 行号


糟糕我忘记了下一步结束之前的声明...


看看是否能解决这个问题..

Oops I forgot the "Next" statement just before the End With...

See if that works it out..


有如上所述的代码导致结束,不结合。编译错误。所以我把它换了一圈(如下图所示),现在我得到了无效或不合格的参考。突出.EOF。


For I = 0 To .EOF

with rcdTesting

.Edit

如果![Outing] = rcdReference![Value]那么

Constant = rcdReference![结果]

结束如果

如果![ Lap] = rcdReference2![Value]然后

Constant2 = rcdReference2![结果]

结束如果

如果![时间] = rcdReference3! [Value]然后

Constant3 = rcdReference3![结果]

结束如果

![Value] .Value = Constant * Constant2 * Constant3

。更新

.MoveNext

结束


有什么想法吗?


感谢您的帮助。
Having the code as stated above resulted in a "end with, without with" compile error. So I''ve swapped it round (as shown below) and now I get "invalid or unqualified reference" highlighting the .EOF.

For I = 0 To .EOF
With rcdTesting
.Edit
If ![Outing] = rcdReference![Value] Then
Constant = rcdReference![Result]
End If
If ![Lap] = rcdReference2![Value] Then
Constant2 = rcdReference2![Result]
End If
If ![Time] = rcdReference3![Value] Then
Constant3 = rcdReference3![Result]
End If
![Value].Value = Constant * Constant2 * Constant3
.Update
.MoveNext
End With

Any ideas?

Thanks for your help.


这篇关于For Each循环对象声明问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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