Solved

Export Access to Word template

Posted on 2008-10-29
3
1,371 Views
Last Modified: 2012-05-05
I  export an access report to a Word Template. Everything is working great.
With the installation of another computer, we want to share the database between the computers, too. Even that is working! The database and the templates are in a Mapped folder.
If I try to create the Word document from the "external" computer, the  code line
'Set doc = wrdApp.Documents.Add(strPath & contemplate)'  is set to NULL. The path and the file name are correct and can be monitored in step mode.
All computers have the right to read and write to the shared drive!
The "external" computer can regerate the word file with the data as a table in it (RTF file)!!
Who can help me?

Josh




    ' Export the data to rtf format
    DoCmd.OutputTo acOutputQuery, conquery, _
     acFormatRTF, strDataSource, False

    ' Start Word using mailmerge template
    Set wrdApp = New Word.Application
    Set doc = wrdApp.Documents.Add(strPath & contemplate)   '<<<======
   
    ' Do the mail merge to a new document.
    With doc.MailMerge
        .OpenDataSource Name:=strDataSource
        .Destination = wdSendToNewDocument
        .SuppressBlankLines = True
        With .DataSource
            .FirstRecord = wdDefaultFirstRecord
            .LastRecord = wdDefaultLastRecord
        End With
        If .State = wdMainAndDataSource Then
            .Execute
        End If
    End With
   
    ' Display the mail merge document
    wrdApp.Visible = True
    wrdApp.WindowState = wdWindowStateMaximize
 
ExitHere:
    doc.Close (wdDoNotSaveChanges)
    Set doc = Nothing
   
    Set wrdApp = Nothing
    Exit Sub
   
HandleErrors:   etc. etc. etc.
0
Comment
Question by:jojahn
  • 2
3 Comments
 
LVL 21

Expert Comment

by:oleggold
ID: 22833226
did You try to add word object to Your vb project?
0
 
LVL 21

Expert Comment

by:oleggold
ID: 22833250
at least Microsoft Office object library,I mean,on external computer
0
 

Accepted Solution

by:
jojahn earned 0 total points
ID: 22840630
The references are the same.
If I copy the database to the external computer and run it, it uses the current path etc...and if the template is there , the software works again.
Here is the code before.....

    Dim strPath As String
    Dim strDataSource As String
   
    Dim doc As Word.Document
    Dim wrdApp As Word.Application
      Const contemplate As String = "Template_1"
      Const conquery As String = "Events_Clients Query_Select_1"
    On Error GoTo HandleErrors
    ' Delete the rtf file, if it already exists.
    strPath = FixPath(CurrentProject.Path)
    strDataSource = strPath & conquery & ".doc"
    Kill strDataSource
   
    ' Export the data to rtf format
    DoCmd.OutputTo acOutputQuery, conquery, _
     acFormatRTF, strDataSource, False

    ' Start Word using mailmerge template
    Set wrdApp = New Word.Application
    Set doc = wrdApp.Documents.Add(strPath & contemplate)

The path is set correctly and I tried to set it as a string to the correct path, I get the same results...

Could it be a timing issue, because it might take some time to access the host. - maybe a security problem, in thai case, why is  the call "strDataSource = strPath & conquery & ".doc"" successful?
Thanks
Josh
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now