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

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

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

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
parkstech
Asked:
parkstech
  • 3
  • 3
1 Solution
 
GrahamSkanCommented:
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
 
parkstechAuthor Commented:
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
 
GrahamSkanCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
parkstechAuthor Commented:
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
 
GrahamSkanCommented:
I'm still here. I gather that Ivan (the Terrible) is well named.
0
 
parkstechAuthor Commented:
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
 
moduloCommented:
PAQed with points refunded (20)

modulo
Community Support Moderator
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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