2

我正在做一个简单的 vba 脚本来查找文件。如果它存在,则将其删除。然后它转到 DoCmd.OutputTo acOutputReport。下面是我正在使用的实际代码的示例。我遇到的问题是当我将自动打开设置为 true 时。我希望文件在导出报告后打开。但是我发现由于某种原因程序停止并会在那里至少停留 5 到 10 分钟,然后它会出错,说远程程序无法完成。出现错误后,文件无论如何都会打开,没有明显的错误...当我将自动打开更改为 false 时。通过手动打开报告,我可以在大约 3 到 5 秒后打开报告。有什么我不知道或找不到导致这个延迟问题的东西吗?

示例代码 - 有些事情可能在语法上是错误的,因为我面前没有代码。但它仍然应该传达我在做什么。

Dim strFile As String
Dim strCon As String
Dim strSQL As String
Dim cnn As Access.Application

strFile = "C:Myfile.rtf"
If Len(Dir(strFile)) Then
Kill strFile
End If

'access connection stuff here

with cnn
     'dont display messages code
     'active connection to my database code
      DoCmd.OutputTo acOutputReport, strFile, acFormatRTF, OutputFile, True
      .Quit
End With

所以我再次遇到的问题是,我似乎无法在访问用报告填充文件后自动打开文件。如果您知道的话,我只是想提高性能或找到解决方法。

4

1 回答 1

3

在从 Access 2007 导出的应用程序中,我将导出操作保存为导出规范并使用:

CurrentProject.ImportExportSpecifications(NameOfSpecification).Execute False

然后我用

Set AppWord = CreateObject(Class:="Word.Application") ' create an instance of Word

Set Doc = AppWord.Documents.Open(NameOfDocument)

AppWord.Visible = True                      ' instance is invisible by default

DoCmd如果有 VBA 方式,我倾向于避免这样做:VBA 给了我更多的控制权。

于 2013-03-22T16:31:10.460 回答