Solved

Get mail merge datasource name

Posted on 2006-07-21
8
320 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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!

 

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…

732 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