Solved

Get mail merge datasource name

Posted on 2006-07-21
8
316 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need VBS version of Excel date conversion 4 70
Excel VBA, find a string in a column, update a cell 7 78
Spell Check in VB6 13 112
Macro Excel - Multiple If conditions 2 72
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…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

776 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