Help Automation not working under Office 2003

D

dixie

I have an Access 2000 application that needs to use automation to open a
merge letter in Word based on a .dot file and end up with a standard
document file (Document1 usually) that has the merged data in it.

The code has worked fine UNTIL one of the sites using the program changed
over to Office 2003. Apart from other problems with being asked for a
digital signature for macros(?) when it opens, the main difference is that
when you press the button to run the procedure to automate with Word (2003
now). What seems to happen is that the *.dot merge file opens and I get a
message stating something along the lines of The file is not a mailmerge
main document. That isn't the actual wording, I am only going from someone
elses description right now as I don't personally have Office 2003 (nor do I
have any early plans of buying it.)

I am in a quandry here as I have to fix this and I do not know why it is
happening. Is there anyone out there who can put me onto the right track or
has also experienced this problem.

What I need to do is to "spawn" a document in Word from a .dot template
which is a mailmerge document. It works in 2000, 2002, but now is not
functional in 2003


The code I am using within my Access program for the automation procedure is
basically as folllows:

'Check to see if the file is already being used



fIsDocFileOpen "f:\letter.dot"



'create an instance of word



Set wrdApp = CreateObject("Word.Application")

wrdApp.Visible = True

Set wrdDoc = wrdApp.Documents.Add "f:\letter.dot



'perform mailmerge



wrdDoc.MailMerge.Execute

wrdDoc.ActiveWindow.WindowState = wdWindowStateMaximize

'close the original form document

wrdDoc.Close wdDoNotSaveChanges



'release references



Set wrdDoc = Nothing

Set wrdApp = Nothing
 
C

Cindy M -WordMVP-

Hi Dixie,

Please get the EXACT wording. What you describe here doesn't ring any bells.

The one thing that would be new with Word 2003 is a prompt about a mail merge
document going to execute SQL. There's a Registry key that can be set to
eliminate this security measure:

"Opening This Will Run the Following SQL Command" Message When You Open a
Word Document - 825765
http://support.microsoft.com?kbid=825765

Other than that, I can only imagine that whatever connection method that was
originally used to connect to the text file is no longer valid on this
installation. Do you have any idea whether you set up the mail merge to use
ODBC or Word's internal text converter? (Note that Word 2002 as well as 2003
will use OLE DB by default when setting up a new connection.)
The code has worked fine UNTIL one of the sites using the program changed
over to Office 2003. Apart from other problems with being asked for a
digital signature for macros(?) when it opens, the main difference is that
when you press the button to run the procedure to automate with Word (2003
now). What seems to happen is that the *.dot merge file opens and I get a
message stating something along the lines of The file is not a mailmerge
main document. That isn't the actual wording, I am only going from someone
elses description right now

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
D

dixie

Hi Cindy,

I have received the exact text of the error message. "This method or
property is not available because the document is not a mail merge main
document.". If I click the OK button, there is an active Word window on the
task bar. This window contains Document1 which appears to be a copy of the
..dot file from which it is created. I can see all of my fields as though it
was a mailmerge document. The mailmerge menu along the top of the screen is
however all "greyed out".

I have looked up the Knowledge Base article you directed me to and I just
have one question about that. It says to place the code
application.DisplayAlerts=wdAlertsNone into a VBA macro. Where would I do
that. Can I put it in my VBA code in Access that runs the automation, or
does it need to go into the Word .dot file (if so, how as I have never done
any stuff like this in Word).

I am finding this very perplexing as everything worked perfectly until Word
2003 came along :>(

dixie
 
C

Cindy M -WordMVP-

Hi Dixie,
I have looked up the Knowledge Base article you directed me to and I just
have one question about that. It says to place the code
application.DisplayAlerts=wdAlertsNone into a VBA macro. Where would I do
that. Can I put it in my VBA code in Access that runs the automation
Yes, you can put any code the article shows into your Access procedure. Just
BUT this is not the key part. The real thing you need to do is make sure
that the Registry key is set for all users who will be using your code. If
all you do is suppress the message, the data still will not be connected.

Also, you should probably build a line into your code that checks whether
the document being opened is actually a merge document so that you can give
the user more useful and understandable messages. Roughly, that would be

If ActiveDocument.MailMerge.MainDocumentType <> wdNotAMergeDocument

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
D

dixie

Cindy, I tried this code in my Access application -
application.DisplayAlerts=wdAlertsNone -, but "DisplayAlerts" is not
recognised when I try to compile it into an mde. What reference library
does it belong to as I have the references Visual Basic for Applications,
Microsoft Access 9.0 Object Library, OLE Automation, Microsoft DAO 3.6
Object Library and Microsoft Word 9.0 Object Library.

dixie
 
C

Cindy M -WordMVP-

Hi Dixie,
Cindy, I tried this code in my Access application -
application.DisplayAlerts=wdAlertsNone -, but "DisplayAlerts" is not
recognised when I try to compile it into an mde. What reference library
does it belong to as I have the references Visual Basic for Applications,
Microsoft Access 9.0 Object Library, OLE Automation, Microsoft DAO 3.6
Object Library and Microsoft Word 9.0 Object Library.
It belongs to the Word library, so you'd need to use the object variable
you declared for the Word application instead of the literal text
"application", as you show above.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
D

dixie

Hi Cindy, I understand what you are saying, but am unsure exactly where to
put the line. Normally, I would just insert it and see the results, but I
don't have Word 2003 here, only 2000 - the problem is occurring at another
site using the application that has just updated to Office 2003. The
following is the gist of the code I use to automate from A2k.

DoCmd.TransferText acExportMerge, "ExportQuery"

Dim wrdApp As Word.Application

Dim wrdDoc As Word.Document

Set wrdApp = CreateObject("Word.Application")

wrdApp.Visible = True

Set wrdDoc = wrdApp.Documents.Add("Template.dot")

wrdDoc.MailMerge.Execute

wrdDoc.ActiveWindow.WindowState = wdWindowStateMaximize

wrdDoc.Close wdDoNotSaveChanges

Set wrdDoc = Nothing

Set wrdApp = Nothing


I send out data to a text file. The mail merge main document is always a
template .dot file which gets its data from text file I send out.

2 questions -
Question 1. I gather the line I should put in will be:
wrdApp.DisplayAlerts = wdAlertsNone
I would put the line after the two dim statements, but I am not 100% sure.
Could you verify that for me.

Question 2. The error message I am now getting when this code is run from
Access using Word 2003 is "This method or property is not available because
the document is not a mail merge main document." Is this caused because
when the mail merge document opens, it is expecting an answer to its
"Opening this will run the following SQL command ...... " message, or is it
because the code I am executing within access is not quite correct and Word
2000 and XP were able to deal with it, but 2003 is not? If this is the
case, could you suggest more correct code for me for Word 2003?

dixie
 
C

Cindy M -WordMVP-

Hi Dixie,
am unsure exactly where to put the line.

Set wrdApp = CreateObject("Word.Application")

wrdApp.Visible = True
'''HERE
wrdapp.DisplayAlerts
Set wrdDoc = wrdApp.Documents.Add("Template.dot")


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
D

dixie

Thanks Cindy. I did some interesting experiments yesterday. I went to one
of the sites with Office 2003 installed. We did the registry change just to
check it. The SQL message that previously started each mail merge
disappeared without using the "wrdApp.DisplayAlerts = wdAlertsNone" code in
the application. Even more interesting - we restored the registry and the
SQL message still did not display! (It may be that the computer needed a
reboot first).

Now, for the other problem which I assume from your lack of a comment, you
have not experienced, so I will add my findings to this newsgroup. About
the error message that says "This method or property is not available
because the document is not a mail merge main document." After playing
around with Word 2003, I discovered that if you create a mail merge main
document in Word 2003 it works as expected from Access. I then tried to
just resave one of my Word 2000 mail merge documents with a "Save As" in
Word 2003. It still refused to work. Then I reconnected the data source to
a Word 2000 mail merge document using Word 2003 and "bingo" it worked as it
should. So, for some reason, Word 2000 mail merge documents need to have
their data sources reconnected using Word 2003 before they will work
properly from Access (I have no idea why this should be so). This means a
lot of work as I have about 70 of these documents at quite a number of
sites, but at least I have found a way of fixing them.

dixie
 
C

Cindy M -WordMVP-

Hi Dixie,

I didn't comment on this because the problem should fix itself as soon as the
Registry entry is in place. If a Word 2000 document was opened in Word 2003,
using your original Access code (or with the DisplayAlerts), then the data
source information has been removed. When this happens, the document
automatically becomes "not a mail merge document". That's why I mentioned that
the "DisplayAlerts" is really not much use for you. And it's also why I
recommended you to check the MainMergeDocumentState in your code so that you
can capture this problem and connect to the data source before having the rest
of the code that's mail merge specific execute.
About
the error message that says "This method or property is not available
because the document is not a mail merge main document." After playing
around with Word 2003, I discovered that if you create a mail merge main
document in Word 2003 it works as expected from Access. I then tried to
just resave one of my Word 2000 mail merge documents with a "Save As" in
Word 2003. It still refused to work. Then I reconnected the data source to
a Word 2000 mail merge document using Word 2003 and "bingo" it worked as it
should. So, for some reason, Word 2000 mail merge documents need to have
their data sources reconnected using Word 2003 before they will work
properly from Access (I have no idea why this should be so).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top