Solved

Get mail merge datasource name

Posted on 2006-07-21
8
319 Views
Last Modified: 2010-04-30
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.
0
Comment
Question by:kncoughlin
  • 4
  • 4
8 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17159275
doc.MailMerge.DataSource.Name

but you might also need

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

0
 

Author Comment

by:kncoughlin
ID: 17160414
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17160555
You need to set the oDoc object.

Set oDoc = Word.Documents.Open(FileName)
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:kncoughlin
ID: 17176886
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
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 17178357
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
 

Author Comment

by:kncoughlin
ID: 17178731
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
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 17178825
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
 

Author Comment

by:kncoughlin
ID: 17178884
T H A N K   Y O U !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question