3

I am using code similar to the below to add some files to a zip folder:

Set oApp = CreateObject("Shell.Application")
oApp.Namespace(CVar(strDest)).CopyHere CVar(strSource)

This works fine most of the time, but sometimes I get an error:

"(Compressed (zipped) Folders Error) Cannot create output file". This error is raised asynchronously outside of my VBA code and as such I cannot trap it to take remedial action.

If I enter break mode and step back to:

oApp.Namespace(CVar(strDest)).CopyHere CVar(strSource)

then the file is added correctly.

I am guessing that there is some kind of lock either on the compressed folder or the source file that is causing this problem, but I am unsure as to how to check this. I should note that the files are being added are pdf files created from Microsoft Access 2007 and we are using the fully qualified paths and the code runs as follows creating up to 10 pdfs per zip file:

  1. Create Zip

  2. Run this loop:

  For Each ReportToRun
    CreatePdf ' using DoCmd.OutputTo acOutputReport, "rptHame", acFormatPDF, strReportName
    AddToZip
  Next

Any idea how to either fix this or trap the Cannot create output file error? Thanks

4

2 回答 2

1

我已经非常成功地使用了开源信息 Zip DLL。有关链接和示例 VB 代码,请参阅压缩 DLL、OCX 等

于 2009-12-21T22:46:20.130 回答
0

两个想法,都不太可能解决问题:

  1. 您是否尝试过明确提供 FALSE 作为下一个参数,即 AutoStart 参数?帮助文件说它默认为 FALSE,但也许它在生成 PDF 后打开它们,以便它们仍然打开?

  2. 添加几秒钟的 SLEEP(有关代码,请参阅使代码进入睡眠状态)。

  3. 或者,循环遍历所有报告并生成所有报告,然后开始一个新循环将每个报告复制到 zip 文件中,而不是为每个报告生成/复制。在两个循环之间休眠几秒钟可能不会受到伤害(假设问题是异步 PDF 生成过程在启动副本时尚未完全完成)。

于 2009-12-22T00:37:52.857 回答