View Single Post
  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
ksg ksg is offline
external usenet poster
 
Posts: 13
Default Automated Mail Merge Displaying unwanted Dialog Boxes

Peter thanks for the quick reply.

Would you be able to point to a place where I can see an example of how to
use ADOX and ADO to create and populate a table in a Jet database.
Thanks
ksg

"Peter Jamieson" wrote:

Word can use at least three different methods to open a plain text file for
use as a data source:
a. its internal text converter. This will pop up a dialog if it doesn't
recognise the field delimiters. There's no way to specify the delimiters in
the OpenDataSource call
b. an OLEDB text provider. This will also typically throw up a prompt
(probably twice, for some reason) for the field delimiter. Again, there is
no way to specify the delimiter in the OpenDataSource call or, as far as I
know, in the OLEDB connection string.
c. an ODBC text driver. In this case, you can specify some of the
characteristics of the file in a SCHEMA.INI file that the driver expects to
find in the same folder as the file you are trying to open.

If your file uses ANSI or the so-called "OEM" character set (i.e. doesn't
use Unicode or any other encoding), and uses CRLF record delimiters and " as
a text delimiter, you can probably open it using ODBC.

To use (c),
d. the ODBC text driver must be installed on the machine where you're doing
the merge
e. you need either a machine (user/system) ODBC DSN or file DSN
f. your OpenDataSource wil lneed to be something like

OpenDataSource _
Name:="", _
Connection:="DSN=yourtextfiledsnname;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

for a machine DSN and

OpenDataSource _
Name:="pathnameofyourdsnfile.dsn", _
Connection:="FILEDSN=pathnameofyourdsnfile.dsn;", _
SQLStatement:="SELECT * FROM [c;\pathname\filename.txt]", _
SubType:=wdMergeSubtypeWord2000

You may also see other dialogs concerning text encoding and so on.

In short, this isn't a particularly good file format to use in order to
automate a Word merge. If you can, use ADOX and ADO to create and populate a
table in a Jet database instead.

Peter Jamieson

"ksg" wrote in message
news
I am writing an application that will accept pipe "|" delimited text files
from other applications to be mail merged when receive. I can pick the
files
up from the directory, open the main mail document and open the data
source;
however when the opendatasource command is executed a dialog box pops up
asking "Text File Connection Properties". I need to pass all the
information
for the mail merge programmatically. This program should run in the
background with no user interaction. I am using Visual Studio - Visual
Basic
- Word 2003. The code I am using is below.

Any help would be appreciated.
'Logic for processing found files here.
Private Sub ProcessFile(ByVal filename As String, ByVal formfilename As
String, ByVal datafilename As String)
Dim wrdApp As Word.Application
Dim wrdDoc As Word._Document
Dim wrdSelection As Word.Selection
Dim wrdMailMerge As Word.MailMerge
Dim wrdMergeFields As Word.MailMergeField
Dim ApplicationDisplayAlerts As Word.WdAlertLevel

' Create an instance of Word and make it invisible.
wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False
ApplicationDisplayAlerts = Word.WdAlertLevel.wdAlertsNone

' Open document.
wrdDoc = wrdApp.Documents.Open(formfilename)
wrdDoc.MailMerge.OpenDataSource(Name:=filename)
wrdMailMerge = wrdDoc.MailMerge()

' Perform mail merge.
wrdMailMerge.Destination = _
Word.WdMailMergeDestination.wdSendToPrinter
wrdMailMerge.Execute(False)

' Close the original form document
wrdDoc.Saved = True
wrdDoc.Close(False)

' Release References.
wrdSelection = Nothing
wrdMailMerge = Nothing
wrdMergeFields = Nothing
wrdDoc = Nothing
wrdApp = Nothing
End Sub 'ProcessFile