Word Automation from Access

A

AJ

I am trying to output some fields from a table to a word merge document. I
have created the word document. When I run my code I get an error at the
".OpendataSource (strTableName). The error says it cannot find the "file". I
know the table is there. Any suggestions? Any help would be appreciated>my
coding is as follows:

Sub MergeWord(strReportName, strTableName)

Dim dbs As DAO.Database
Dim wApp As Object
Dim wDoc As Object
Dim wActiveDoc As Word.Document

Set dbs = CurrentDb
Set wApp = CreateObject("Word.Application")

Set wDoc = wApp.Documents.Open(strReportName)
With wDoc.MailMerge
.OpenDataSource (strTableName)
.Destination = wdSendToNewDocument
.Execute
End With
Set wActiveDoc = wApp.ActiveDocument
wActiveDoc.Visible = True

Set dbs = Nothing
Set rst = Nothing
Set wApp = Nothing
Set wDoc = Nothing
Set wActiveDoc = Nothing

End Sub

Thank You
 
M

Maurice

Shouldn't you provide the location of the strReportName. My guess is that the
file can be found but your routine doesn't know where to look for it...

maybe something like:

Set wDoc = wApp.Documents.Open("c:\your location\ " & strReportName)

hth
 
A

AJ

I pass the location in the call statement of another module. It is actually
the table that the error code says it cannot find..Which I pass also in the
call statement.
 
R

ROSCECAN

AJ said:
I am trying to output some fields from a table to a word merge document. I
have created the word document. When I run my code I get an error at the
".OpendataSource (strTableName). The error says it cannot find the "file".
I
know the table is there. Any suggestions? Any help would be appreciated>my
coding is as follows:

Sub MergeWord(strReportName, strTableName)

Dim dbs As DAO.Database
Dim wApp As Object
Dim wDoc As Object
Dim wActiveDoc As Word.Document

Set dbs = CurrentDb
Set wApp = CreateObject("Word.Application")

Set wDoc = wApp.Documents.Open(strReportName)
With wDoc.MailMerge
.OpenDataSource (strTableName)
.Destination = wdSendToNewDocument
.Execute
End With
Set wActiveDoc = wApp.ActiveDocument
wActiveDoc.Visible = True

Set dbs = Nothing
Set rst = Nothing
Set wApp = Nothing
Set wDoc = Nothing
Set wActiveDoc = Nothing

End Sub

Thank You
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top