Get mail merge datasource name

I need to be able to open a mail merge document in VB (which I can do) but I need to be able to extract the datasource name embedded in the file.
kncoughlinAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
GrahamSkanConnect With a Mentor RetiredCommented:
That's a security feature, but there is a registry mod for it:

http://support.microsoft.com/default.aspx?scid=KB;EN-US;825765
0
 
GrahamSkanRetiredCommented:
doc.MailMerge.DataSource.Name

but you might also need

doc.MailMerge.DataSource.ConnectString
and/or
doc.MailMerge.DataSource.QueryString

0
 
kncoughlinAuthor Commented:
I had tried that already and got an error 91...object variable or with block variable not set.  Here's my code:

Dim oWord As Word.Application
Dim oDoc As Word.Document

Set oWord = New Word.Application
oWord.Visible = True
oWord.Documents.Open (filename)
MsgBox oDoc.MailMerge.DataSource.name
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
GrahamSkanRetiredCommented:
You need to set the oDoc object.

Set oDoc = Word.Documents.Open(FileName)
0
 
kncoughlinAuthor Commented:
Unfortunately, it is coming up blank with the name.  I don't know if the fact that I'm using a comma delimited txt file for my datasource has anything to do with it.
0
 
GrahamSkanRetiredCommented:
It works for me with a CSV file. It returns the full file name.

What value do you get for the Type property?

MsgBox oDoc.MailMerge.DataSource.Type
0
 
kncoughlinAuthor Commented:
I'm getting a -1.  When I try to open the document thru Word (no VB intervention) I'm getting the following message:

Opening this document will run the following SQL command:

SELECT * FROM C:\TEST.txt

Data from your database will be placed in the document.  Do you want to continue?

I'm guessing that until this question is answered, it does not embed the datasource.  Perhaps that's why the VB is not seeing it.

Thanks in advance for all your help....I'll up the points.
0
 
kncoughlinAuthor Commented:
T H A N K   Y O U !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.