Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.mailmerge.fields
janlabe janlabe is offline
external usenet poster
 
Posts: 6
Default Tab delimited data source

I have a mailmerge data source created by a DOS program that I have been
using for 13 years through several version of Word (I'm on Word 2002 now).
For some reason, Word sometimes loses track of the data source and I have
never figured out how to reattach it short of copying in an archived copy of
the merge doc. I go through all the steps of manually attaching the file,
but it always says the records are empty (which they aren't). I have tried
all encoding options. It is a simple file with tabs between fields and 0x0D
between records. The file is fine.

How does one attach a tab delimited .txt file as a merge data source?
  #2   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default Tab delimited data source

Word is normally quite relaxed about data sources for mail merge and a tab
delimited text file should not cause it any grief.

The following macro will re-attach the data source named in it to the
current document. However you could make things simpler for Word by
converting the data file to a Word table - see
http://www.gmayor.com/convert_labels...mail_merge.htm and storing the
data source either in the same folder as the merge document or in the 'My
Data Sources' folder. You should also check for orphan lock files which
prevent Word from operating correctly - see
http://www.gmayor.com/what_to_do_when_word_crashes.htm

Sub AttachData()
With ActiveDocument.MailMerge
.MainDocumentType = wdNotAMergeDocument
.MainDocumentType = wdFormLetters
.OpenDataSource name:= _
"D:\My Documents\Test\Tab Delimited Data.txt", _
ConfirmConversions:=False, _
ReadOnly:=False, _
LinkToSource:=True, _
AddToRecentFiles:=False
End With
End Sub
http://www.gmayor.com/installing_macro.htm

--

Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org


janlabe wrote:
I have a mailmerge data source created by a DOS program that I have
been using for 13 years through several version of Word (I'm on Word
2002 now). For some reason, Word sometimes loses track of the data
source and I have never figured out how to reattach it short of
copying in an archived copy of the merge doc. I go through all the
steps of manually attaching the file, but it always says the records
are empty (which they aren't). I have tried all encoding options.
It is a simple file with tabs between fields and 0x0D between
records. The file is fine.

How does one attach a tab delimited .txt file as a merge data source?



  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Tab delimited data source

If your records are definitely only delimited by 0x0D (CR) and not
0x0D0A (CRLF) then you may find that
a. Word always pops up the dialog that asks you for the field and
record delimiters
b. even when you say tab and enter, no records are found.
c. Graham's code also forces you to respond to that dialog.

I can't check in Word 2002 right now but in Word 2003 or 2003 I believe
what you actually need is something along the following lines. (Let's
suppose your file is called myfile.txt and is in folder c:\a ) :

1. A file called schema.ini in the same folder as myfile.txt. There may
already be one there. It's a text file that you can edit in Notepad.
What you need is some lines like this:

[myfile.txt]
ColNameHeader=True
Format=TabDelimited
MaxScanRows=25
CharacterSet=OEM

(It's possible that you would need something other than OEM in that last
line).

2. A completely empty "Office Data Connection" (.odc) file. You can
create an empty file in Notepad and rename it. Let's say it's called

c:\a\empty.odc

3. A different bit of Word VBA to set up the data source, e.g.:

Sub AttachData()

Dim strFolder As String
Dim strODCFile As String
Dim strConnection As String
Dim strQuery As String
Dim strTextFile As String

' Use your folder name...
strFolder = "c:\a\"

' Use your .odc name...
strODCFile = strFolder & "empty.odc"

' Use your text file name...
strtextFile = "myfile.txt"

' Build the connection string
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Mode=Read;" & _
"Jet OLEDB:Engine Type=96;DataSource=" & _
strFolder & ";"

' Build the Query string
strQuery = "SELECT * FROM [" & strTextFile & "]"

' Open the data source

With ActiveDocument.MailMerge
.MainDocumentType = wdNotAMergeDocument
.MainDocumentType = wdFormLetters
.OpenDataSource _
Name:=strODCFile, _
Connection:=strConnection, _
SQLStatement:=strQuery
End With

End Sub


Peter Jamieson

http://tips.pjmsn.me.uk

janlabe wrote:
I have a mailmerge data source created by a DOS program that I have been
using for 13 years through several version of Word (I'm on Word 2002 now).
For some reason, Word sometimes loses track of the data source and I have
never figured out how to reattach it short of copying in an archived copy of
the merge doc. I go through all the steps of manually attaching the file,
but it always says the records are empty (which they aren't). I have tried
all encoding options. It is a simple file with tabs between fields and 0x0D
between records. The file is fine.

How does one attach a tab delimited .txt file as a merge data source?

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
export form data to tab-delimited file? michalaw Microsoft Word Help 0 March 31st 08 02:02 PM
Saving Table data in txt format Tab delimited? Can it be done? How Red Tables 5 March 19th 08 09:09 AM
Mail Merge - Comma delimited data into table ocbarney Mailmerge 3 August 15th 06 08:12 PM
How to link a different Mailmerge header source and data source? Eleni_Malli Mailmerge 1 May 3rd 06 02:08 PM
data in mail merge letter being cut off - data source field size? tgone Mailmerge 1 May 20th 05 02:10 PM


All times are GMT +1. The time now is 04:08 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"