Solved

VB6 and using an existing .dot template for Word Mail Merge

Posted on 2004-09-08
9
613 Views
Last Modified: 2010-05-02
I have already done this where I am creating the document from Visual Basic but what I need to know is this.

The users want to be able to create their own template for the Mail Merge then select the path to that document in my app and run the merge process.  I have been researching this for 2 weeks and I have found nothing where this can be done.  I know it sounds like we are reinventing the wheel or rewriting Microsoft Word but I work with day traders that have very little computer knowledge.

To date I can call the template document and open it in code however I have not been able to physically produce a document with data from the data source in my application.

I have tried several examples from this site and many other sites but nothing appears to work.

Would someone be kind enough to point me in the right direction please.

Thanks,
Kevin
0
Comment
Question by:parkstech
[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
  • 3
  • 3
9 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 12017151
I'm trying to underxstand your problem.
Do you just need to provide a means to browse for the template file in your VB application? What does you application contribute to the MailMerge process? Do you need VB to run the MailMerge, or is it just emulating a mail merge process?
0
 

Author Comment

by:parkstech
ID: 12019760
I have the browse part developed using the Common Dialog control.

I can create the merge document from code with no problem.  What they want is to create their own merge templates and then I am suppoased to call the template to run the merge.  Thus far I can open the template using the following:

Set odoc = oWord.Documents.Add("F:\Docs\ADMIN\OPS\Client Labels\Labels\REPGEN_ADProj\Dev\merge_template.dot")

It works to this point.  I have an ADO datasource already in the code.  In this I have a field called "Name" and in the merge template I have a Merge Field called "Name".

I want to populate the existing Merge Field "Name" with the value from the ADO recordset.

I tried this:  .Fields.Item(1).Data = "" + adoPrimaryRS.Fields(1).Value + ""

It gives me an error of:  Cannot insert data into this field.

If possible I need to know how to update the Merge Field in the template document from the recordset.


Thanks for looking at this,
Kevin


0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 12019904
Hi Kevin,
At first glance, this looks possible, but complex. It's now 19:44 (7:44pm ) here in the UK, so I'm going off-line now. If no-one else, who is more active in the intervening hours, has substantial input in about 12 hours, I'll try to formulate a more useful answer in my morning.
Graham
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:parkstech
ID: 12019944
Ok, thanks.  I am in Florida so if you cannot tomorrow then maybe Monday or Tuesday.  If Hurricane Ivan continues on it's path then I don't know.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 12020055
I'm still here. I gather that Ivan (the Terrible) is well named.
0
 

Author Comment

by:parkstech
ID: 12022923
We have a little humor going around here.

Emergency plan for Miami:

1.  Stand up
2.  Face North
3.  Bend over and grab your ankles

Here comes Ivan!!!

========================================================

I figured out most of this but I have a popup dialog problem and I am not sure where it is coming from or what it means.  We are using Word 2002 (XP).  

Read the comment next to the Execute statement

Option Explicit

Dim objWord As Word.Document
Dim docSql As String

Public db As ADODB.Connection
Dim WithEvents adoPrimaryRS As ADODB.Recordset

Private Sub Command1_Click()

  Dim sDBPath As String

  Set db = New Connection
  db.CursorLocation = adUseClient

  db.Open "Provider=SQLOLEDB.1;Password=dev1;Persist Security Info=True;User ID=sa;Initial Catalog=ADV_REPGEN;DataSource=ITDEV1"

  docSql = "SELECT TOP 1 ID, Name, Attn, Addr1, Addr2, City, State, Zip, LFO, pkg " & _
                "FROM dbo.VW_CVR_PG_DATA " & _
                "GROUP BY ID, Name, Attn, Addr1, Addr2, City, State, Zip, LFO, pkg " & _
                "ORDER BY Name "

  Set adoPrimaryRS = New Recordset
  adoPrimaryRS.Open docSql, db, adOpenStatic, adLockOptimistic

  Set objWord = GetObject("F:\Docs\ADMIN\OPS\Client Labels\Labels\REPGEN_ADProj\Dev\ama_merge.dot", "Word.Document")

  ' Make Word visible.
  objWord.Application.Visible = False

  ' Set the mail merge data source.
  sDBPath = "F:\Docs\ADMIN\OPS\Client Labels\Labels\REPGEN_ADProj\Dev\REPGEN.adp"

  objWord.MailMerge.OpenDataSource Name:=sDBPath, _
  SQLStatement:="" + docSql + ""

  ' Execute the mail merge.
  objWord.MailMerge.Execute Pause:=False  '< This runs but a dialog comes up.  If I click OK or Cancel the merge completes successfully.  I can't get rid of the dialog box and it doesn't give me a clue to what it is expecting.

End Sub

Private Sub Form_Unload(Cancel As Integer)
  End
End Sub
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12735879
PAQed with points refunded (20)

modulo
Community Support Moderator
0

Featured Post

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!

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.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 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