Word Automation from Access

  • Follow


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
0
Reply Utf 2/21/2008 8:19:01 PM

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
-- 
Maurice Ausum


"AJ" wrote:

> 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
0
Reply Utf 2/21/2008 8:33:00 PM


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. 

"Maurice" wrote:

> 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
> -- 
> Maurice Ausum
> 
> 
> "AJ" wrote:
> 
> > 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
0
Reply Utf 2/25/2008 2:16:01 PM

"ROSCECAN@ HOT MAIL.COM" <ROSCECAN@ HOT MAIL.COM> wrote in message 
news:OstVKrQiIHA.4844@TK2MSFTNGP06.phx.gbl...
>
>
> "AJ" <AJ@discussions.microsoft.com> escreveu na not�cia da 
> mensagem:7F2C6522-5472-4E1E-BF63-A543773024E1@microsoft.com...
>> 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
> 

0
Reply leoladouceur 3/18/2008 10:11:05 PM


"AJ" <AJ@discussions.microsoft.com> escreveu na not�cia da 
mensagem:7F2C6522-5472-4E1E-BF63-A543773024E1@microsoft.com...
> 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 

0
Reply ROSCECAN 3/19/2008 3:15:18 PM

4 Replies
323 Views

(page loaded in 0.002 seconds)

Similiar Articles:
















7/31/2012 6:10:32 AM


Reply: