[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

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.
0
kncoughlin
Asked:
kncoughlin
  • 4
  • 4
1 Solution
 
GrahamSkanCommented:
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
 
GrahamSkanCommented:
You need to set the oDoc object.

Set oDoc = Word.Documents.Open(FileName)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
GrahamSkanCommented:
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
 
GrahamSkanCommented:
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
 
kncoughlinAuthor Commented:
T H A N K   Y O U !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now