如何等待紧致修 - 访问VBA [英] How to wait for Compact Repair - Access VBA
问题描述
有一个VBA模块访问2007年它执行了类似的行动For循环。 在每一个循环我想压缩并在进行下一次迭代之前修复当前数据库的末尾。
Have a VBA Module in Access 2007 which performs similar actions in a For loop. At the end of every loop I wish to compact and repair the current database before proceeding to the next iteration.
原因:在每次迭代创建,用于计算和删除表。 规模应保持在控制之下。
Reason : In every iteration I create , use for calculation and delete a table. The size should remain under control.
使用的SendKeys,我不能压缩和修复 - 如果调用从表单按钮模块。 任何诀窍,以确保SendKey工作正常,则模块将继续到下一次迭代完美无缺。有些想法控制表加载/模块执行/检查状态等。 最终目的是要等待足够长的时间,直到压实完成,然后继续前进。另外如何安全保证的SendKeys /(建议备用),压实效果还算不错。
Using SendKeys , I cannot compact and repair - if calling the module from a Form Button. Any trick to ensure that the SendKey works fine and the Module continues onto the next iteration flawlessly. Some idea to control Form loading / Module execution / Checking Status etc. End Purpose being to wait just long enough till the Compacting is done and then move on. Also how to safely ensure that SendKeys / (suggest alternate) for compacting works fine.
感谢
推荐答案
......在for循环中,在每一个循环我想压缩并在进行下一次迭代之前修复当前数据库的结尾。的
考虑一下,当你压缩当前数据库中实际发生的事情。访问首先创建当前数据库作为的新的数据库文件的压缩版本。然后,它会删除旧的数据库文件,重命名为新的文件的旧名称,终于打开新的数据库文件。
Consider what actually happens when you compact the current database. Access first creates a compacted version of the current database as a new db file. Then it deletes the old db file, renames the new file to the old name, and finally opens the new db file.
所以,如果你的code通过为
环......试图紧凑每个周期中当访问,然后打开该压缩的数据库文件......会是怎样知道你希望它继续在该为
循环?
So if your code attempted compact each cycle through a For
loop ... when Access then opens the compacted db file ... how would it know you wanted it to continue in that For
loop?
如果你真正想要做这样的事情,你将不得不储存的值来记录这是的最后一次迭代
循环。然后创建一个自动执行的宏检索在数据库打开该值,然后输入为
循环在适当的周期。然后决定你是否真的想所有发生在每次打开数据库时。
If you truly want to do something like that, you will have to store a value to record which was the last iteration of the For
loop. Then create an autoexec macro to retrieve that value at database open, and enter the For
loop at the appropriate cycle. And then decide whether you really want that all to happen every time the database is opened.
不过这似乎是太多精力在我身上。它应该是简单的使用另外一个数据库文件来保存你的非易失性数据。然后,从code在当前的的数据库,你可以使用的 DBEngine.CompactDatabase 压缩外部数据库文件。
However that seems like too much effort to me. It should be simpler to use another db file to hold your volatile data. Then from code in the current database you can use DBEngine.CompactDatabase to compact the external db file.
这篇关于如何等待紧致修 - 访问VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!