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 / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Merging with a macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Donna - 04 Jan 2006 18:12 GMT
I have a macro that merges serveral documents with an Access database and
then combines all the document together. When I try the macro in Word 2003, I
get an alert message for each merge document "Opening this document will run
an SQL statement...". You have to click on Yes for each document. If I use
the "Application.DisplayAlerts = wdAlertsNone" function, it does not display
the message, but it default to No. I need it to default to Yes. How do I
respond to the message automatically?
Signature

Donna

Cindy M  -WordMVP- - 05 Jan 2006 11:07 GMT
Hi =?Utf-8?B?RG9ubmE=?=,

> I have a macro that merges serveral documents with an Access database and
> then combines all the document together. When I try the macro in Word 2003, I
[quoted text clipped - 3 lines]
> the message, but it default to No. I need it to default to Yes. How do I
> respond to the message automatically?

See this article

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

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :-)
Donna - 05 Jan 2006 14:45 GMT
Thanks for the link to the article. Since my macro will run on many different
computers do you know of any programming code that I can use in the macro to
capture the alert and respond to it?
Signature

Donna

> Hi =?Utf-8?B?RG9ubmE=?=,
>
[quoted text clipped - 19 lines]
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)
zkid - 08 Jan 2006 23:11 GMT
I feel your pain.  I'm sure you've noticed that 97 and 2000 have their own
way of merging, XP again is different, and 2003 is different still.  So, you
will need to test for the Office version and apply the appropriate merge code
for each.  It's not that difficult to do - let me know if you need the code.

Bottom line is that in 2003, you need code similar to the following:

(From 2003 help)
This example uses ODBC to attach the Microsoft Access database named
"Northwind.mdb" to the active document. The SQLStatement argument selects the
records in the Customers table.

Dim strConnection As String

With ActiveDocument.MailMerge
   .MainDocumentType = wdFormLetters
   strConnection = "DSN=MS Access Databases;" _
       & "DBQ=C:\Northwind.mdb;" _
       & "FIL=RedISAM;"
  .OpenDataSource Name:="C:\NorthWind.mdb", _
       Connection:=strConnection, _
       SQLStatement:="SELECT * FROM Customers"
End With

The problem here is that you need to fill in the SQLStatement.  As far as I
know (and believe me, I've tried), the only way to turn off the SQL prompt is
to actually retrieve all of your main documents and tell them not to connect
to the datasource.  Then re-save and close.  Once you have inserted all of
the merge fields that you need, unlnking the main doc from the datasource
shouldn't create any problems.  If you ever need to insert more fields, you
can always re-connect it manually, temporarily.

I had to punt by doing the above, because I have not succeded in "capturing"
the SQL prompt and dealing with it.  Anyone else been able to do it?

zkid

> Thanks for the link to the article. Since my macro will run on many different
> computers do you know of any programming code that I can use in the macro to
[quoted text clipped - 23 lines]
> > This reply is posted in the Newsgroup; please post any follow question or reply
> > in the newsgroup and not by e-mail :-)
Cindy M  -WordMVP- - 09 Jan 2006 16:18 GMT
Hi =?Utf-8?B?emtpZA==?=,

> I had to punt by doing the above, because I have not succeded in "capturing"
> the SQL prompt and dealing with it.  Anyone else been able to do it?

Which version of Word are we talking about, in this case? The SQL prompt should
never appear when opening a main merge document using automation. The data
source should be disconnected automatically, with no prompt.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
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 :-)
Donna - 12 Jan 2006 16:31 GMT
I am using Word 2003. I ended up doing the link after I open the document. I
was surprised that it did not increase the amount of time it takes to run the
macro. There are 5 different merge documents that get opened, linked and
combined into a single document and the whole thing takes under 30 seconds.
Works for me!
Signature

Donna

> Hi =?Utf-8?B?emtpZA==?=,
>
[quoted text clipped - 12 lines]
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)

Rate this thread:






 
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.