[英]Access VBA Loop with Dcount Condition
rcount = DCount("F1", "T1")
Do While rcount > 0
DoCmd.OpenQuery "q1"
Loop
Can anyone tell me while this code won't work? 谁能告诉我这段代码不起作用? It loops through, but seemingly ignores the condition of
rcount > 0
它循环,但似乎忽略了
rcount > 0
的条件
Update the value of rcount after you execute the delete query. 执行删除查询后,更新rcount的值。
rcount = DCount("F1", "T1")
Do While rcount > 0
'DoCmd.OpenQuery "q1"
CurrentDb.Execute "q1", dbFailOnError
rcount = DCount("F1", "T1")
Loop
Note by using CurrentDb.Execute
instead of DoCmd.OpenQuery
, you can avoid the confirmation messages without turning SetWarnings
off. 请注意,通过使用
CurrentDb.Execute
而不是DoCmd.OpenQuery
,可以避免确认消息而无需关闭SetWarnings
。 And it also allows you to use dbFailOnError which will notify you about problems which would otherwise fail silently. 而且,它还允许您使用dbFailOnError ,它将通知您有关可能会静默失败的问题。
However I don't understand why you want to delete all the T1 records one at a time when you could remove them all at one go ... 但是我不明白为什么您想一次删除所有T1记录,而一次却可以删除它们呢?
CurrentDb.Execute "DELETE FROM T1;", dbFailOnError
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.