Reply
 
Thread Tools Display Modes
  #1   Report Post  
ucmlamb ucmlamb is offline
Junior Member
 
Posts: 2
Default Mailmerge doc will not open from Access 2003

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
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson
 
Posts: n/a
Default Mailmerge doc will not open from Access 2003

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
"ucmlamb" wrote in message
...

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


--
ucmlamb



  #3   Report Post  
ucmlamb ucmlamb is offline
Junior Member
 
Posts: 2
Default

Thanks for your reply. I made one change that fixed this.
1. I called "WordApp.ActiveDocument.MailMerge.OpenDataSour ce" 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

Quote:
Originally Posted by Peter Jamieson
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
"ucmlamb" wrote in message
...

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


--
ucmlamb
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word applies direct format on File open Uriel Microsoft Word Help 16 November 27th 05 07:22 PM
Word 2003 slow to open Word 2003 Virus Scanning STOP Microsoft Word Help 0 August 15th 05 12:38 AM
Access to Word link 2003 Jack Mailmerge 4 August 8th 05 05:43 PM
How to use access query computed fields in Word mailmerge Rey Mailmerge 5 June 23rd 05 06:26 PM
Word 2003 Hangs when I try to Open a Doc -=Tarik=- Microsoft Word Help 1 May 19th 05 05:58 AM


All times are GMT +1. The time now is 08:42 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"