Word Automation from Access

  • Thread starter Thread starter AJ
  • Start date Start date
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
 
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
 
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.
 
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
 
Back
Top