Exporting MS access Report to MS Word using VBA

14,985

In an application which exports from Access 2007, I saved the export operation as an export specification and used :

CurrentProject.ImportExportSpecifications(NameOfSpecification).Execute False

I then used

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

I tend to avoid DoCmd if there's a VBA way of doing it: VBA gives me more control.

Share:
14,985
divdeamor
Author by

divdeamor

Updated on June 04, 2022

Comments

  • divdeamor
    divdeamor almost 2 years

    I am doing a simple vba script that looks for a file. If it exsits it deletes it. then it moves on to the DoCmd.OutputTo acOutputReport. Below is the an example of the actual code i am using. The problem i am running into is when i set the auto open to true. I want the file to open after it exports the report. However i am finding that for some reason the program stalls and will sit there for atleast 5 to 10 minutes then it will error out saying that the remote proceedure can not be completed. After the error the file opens anyway with no apparent errors... When i change the auto open to false. I am able to open the report in about 3 to 5 seconds later by manually opening it. Is there something i do not know or can not find that is causing this latancy issue?

    Example code - Some things might be syntacticly wrong as i dont have the code infront of me. But it should still communicate what im doing.

    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
    

    so again the issue i am having is that i can not seem to get the file to automatically open after access populates it with the report. I am simply trying to increase the preformance or find a work around if you know of any.

  • divdeamor
    divdeamor about 11 years
    Never Mind i just had to move the visable tag to a new spot works like a charm thanks.
  • grahamj42
    grahamj42 about 11 years
    Sorry, I cut this out of a much larger file. Example updated.