I gave it a try and now have a new problem. When I reopen the document, I
receive an error message that the data source cannot be found.
Aargh! This problem has come up before, but only in some circumstances. A
couple of things to check
a. is Windows Explorer set up to display file extensions? If not, please
change the value in Explorer Tools|Folder Options|View and try again. But if
your connection saved successfully before, I doubt if that is the problem
b. Does the name of the column you are using for the filter contain any
spaces? If so, you will either need to create a View in SQL Server or
connect some other way (ODBC+MS Query probably) in which case this route is
probably not going to save you any time and a bit of VBA may be needed
anyway.
If neither of those things is applicable, the simplest way to set up the
merge data source using VBA would probably be as follows:
a. create an AutoOpen subroutine in the document (see
http://word.mvps.org
for further info on this, including other ways to get macros to run
automatically. The sub should contain at least
Sub AutoOpen()
' Needs error management...
With ActiveDocument.MailMerge
' Substitute the main document type you need
.MainDocumentType = wdFormLetters
.OpenDataSource _
Name:="the full path name of the .odc file you set up", _
Connection:="can be blank I think, or contain any additional connection
info you need", _
SQLStatement1:="the SQL query you need"
' Substitute the default destination you want (the users will override
this anyway)
.Destination = wdSendToNewDocument
End With
End Sub
b. test the macro
c. make the document a "normal" Word document (which removes the data
source. You can do this using the first button in the mail merge toolbar or
using VBA:
ActiveDocument.Mailmerge.MainDocumentType = wdNotAMergeDocument
d. save and close the document.
e. open the document and verify that you see the records you need.
If that works then it would not be a large step to add code to prompt for a
Customer ID.
If you still lose the connection on open then I would guess some security
info is missing.
You may be able to discover the query syntax required by using
print ActiveDocument.Mailmerge.DataSource.QueryString
in the Visual Basic immediate window with your existing, working document
open.
If Word does not let you do that, save the document as a "Web Page", open it
as a text file so you can see the HTML, and you will find the connection
info. and query info in a block near the top of the file.