Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / March 2006

Tip: Looking for answers? Try searching our database.

Mailmerge doc will not open from Access 2003

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ucmlamb - 06 Mar 2006 21:01 GMT
I am using Access 2003 to open a Mail Merge document using the following
VB code.  The document uses a text file as the datasource.  This worked
in Access 2000, but the document will not open in Access 2003, word
opens and the status bar displays "docname.doc: 1,222 characters..."
then the document never opens.  If I remove the "WordDoc.Close (False)"
line the document will display, but not with the updated merge data from
the datasource, instead it opens with the saved data from the "template"
or original merge document.  As I said this code works perfectly in
earlier versions of Access.

Function MergeWord(strDocName As String)
Dim WordApp       As Object            ' running instance of word
Dim WordDoc       As Object            ' one instance of a word doc
Dim strActiveDoc  As String            ' doc name (no path)
Dim lngWordDest   As Long              ' const for dest, 0 = new
doc, 1 = printer

On Error GoTo CreateWordApp
Set WordApp = GetObject(, "Word.Application")
On Error Resume Next

Set WordDoc = WordApp.Documents.Open(strDocName)

strActiveDoc = WordApp.ActiveDocument.Name

With WordDoc.MailMerge
.Destination = 0        ' 0 = new doc
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = 1
.LastRecord = 1
End With
.Execute Pause:=True
End With
WordDoc.Close (False)

WordApp.Visible = True
WordApp.Windows(WordApp.Windows.Count).Activate

AppActivate "Microsoft Word"
WordApp.WindowState = 0 'wdWindowStateRestore

Set WordApp = Nothing
Set WordDoc = Nothing

DoEvents
Exit Function

CreateWordApp:
..
End Function

Any help would be appreciated.
Thanks
ucmlamb

Signature

ucmlamb

Peter Jamieson - 07 Mar 2006 08:42 GMT
I can't be sure, but I suspect you need to follow the instructions in this
Knowledgebase article:

"Opening This Will Run the Following SQL Command" Message When You Open a
Word Document"

at

http://support.microsoft.com?kbid=825765

However, it the data source being generated by Access just before you open
the Word document, or is it already there? If it has just been generated,
you may be encountering another problem where Access (or perhaps a virus
checker) still has the file locked. It may be worth trying to experiment
with a data source that has not /just/ been created to see if it makes any
difference.

Peter Jamieson

> I am using Access 2003 to open a Mail Merge document using the following
> VB code.  The document uses a text file as the datasource.  This worked
[quoted text clipped - 54 lines]
> Thanks
> ucmlamb
ucmlamb - 07 Mar 2006 16:00 GMT
Thanks for your reply.  I made one change that fixed this.
1.  I called "WordApp.ActiveDocument.MailMerge.OpenDataSource" after
opening the document.

Here is the code sample:
..
Set WordDoc = WordApp.Documents.Open(strDocName)

strActiveDoc = WordApp.ActiveDocument.Name
strPathName = WordApp.ActiveDocument.Path
strTempName = strPathName + "\" +
GetFileName_NoExtension(strActiveDoc) + ".888"

On Error GoTo ERROR_HANDLER

'Open the text file data source and process the mail merge
WordApp.ActiveDocument.MailMerge.OpenDataSource Name:= _
strTempName _
, ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=0, Connection:="", SQLStatement:="", SQLStatement1 _
:=""
With WordApp.ActiveDocument.MailMerge
.Destination = 0        ' 0 = new doc
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = 1
.LastRecord = 1
End With
.Execute Pause:=True
End With

WordDoc.Close (False)
..

Fortunately this change seems to also work for previous versions of
Access as well.

Thanks
ucmlamb

Peter Jamieson Wrote:
> I can't be sure, but I suspect you need to follow the instructions in
> this
[quoted text clipped - 88 lines]
> --
> ucmlamb

Signature

ucmlamb

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.