Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Merge Doc Won't Work When Opened Through Access VBA

Status
Not open for further replies.

Dor100

Technical User
Apr 9, 2001
279
US
Problem: Have a Word XP merge doc using an Excel XP spreadsheet as data source. When you open the doc by itself, it opens as a merge doc and recognizes the data source (Me.ActiveWindow.Document.MailMerge.DataSource.Name = "Path-Plus-File Name"). When you open the same document from an Access XP database through VBA (Word.Documents.Open FileName:="G:\Folder\FileName.doc", ReadOnly:=False) it does not work as a merge document, and Me.ActiveWindow.Document.MailMerge.DataSource.Name = "".

What is causing this discrepancy? How can I solve it so the merge doc opens correctly through Access VBA? Thanks...
 
How about a Document_Open event from Word, or

With ActiveDocument

Something...?

End With

from Access?...Still searching...
 
When in word menu Tools -> Options -> tab General -> Tick confirm conversions on open.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks, PHV, but unfortunately everything stayed the same.
 
I'm getting closer:

With ActiveDocument

If .MailMerge.DataSource.Name = "" Then

.MailMerge.OpenDataSource ("G:\Folder\File.xls")

End If

Now it opens the Select Table window along with the Word doc, as if you were opening a data source manually. I would like that step to be automated too because I cannot expect users to deal with it. The options in the window are: Sheet Name, 'Sheet Name$', and Named Data Range (this is an Excel spreadsheet, as mentioned above). I do not know why the second option with the single quotes and dollar sign appears. I would like to automate selection of the first option.
 
Yup:

With ActiveDocument

If .MailMerge.DataSource.Name = "" Then

.MailMerge.OpenDataSource "G:\Folder\File.xls", _
LinkToSource:=True, _
SQLStatement:="SELECT * FROM [Named Range]"


End If

End With

Now all I need to do is get the reveal-field-codes business under control, but that part can be left to the user if necessary.
 
At last:

.MailMerge.ViewMailMergeFieldCodes = False
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top