Solved

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

Posted on 2004-09-08
9
594 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
  • 3
  • 3
9 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
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
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:parkstech
Comment Utility
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
Comment Utility
I'm still here. I gather that Ivan (the Terrible) is well named.
0
 

Author Comment

by:parkstech
Comment Utility
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
Comment Utility
PAQed with points refunded (20)

modulo
Community Support Moderator
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now