p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Access 2003 VBA Programmer's Reference (http://p2p.wrox.com/forumdisplay.php?f=133)
-   -   Access automation (http://p2p.wrox.com/showthread.php?t=15209)

william.murray July 9th, 2004 07:59 AM

Access automation
Hi - I was wondering if someone could help me? I'll start at the begining: I need a user to open a word document (from Access) which has some static text(mail merge) and I need to append data from a form to it. This isn't a problem I've used the basic code shown in the automation chapter (sorry at work and can't remember the chapter nr) with some slight modifications - API call to CMDLG32.dll assigning the file name to a string and passing the string to the getobject function as a parameter. Now the problem starts I get 2 word documents opened, the merge template document and another "Formdocument" both with the same info? Is it possible only to open the new document with all the staic and dynamically assigned text?

Code snippit below. (Be kind to me I'm new to this game ;o))

Private Sub CmdGetCmnDlg_Click()
On Error GoTo Err_CmdGetCmnDlg_Click

Dim strPath As String
Dim WordDoc As Word.Document

strPath = GetFile

If (strPath = "") Then
  Exit Sub

Set WordDoc = GetObject(strPath)
WordDoc.Application.Visible = True

WordDoc.MailMerge.OpenDataSource *****...................etc

Cheers Wullie[xx(]


tlwaltz July 27th, 2004 10:09 AM

I just received a copy of this book. Although I don't use Word very much, I was intrigued by your question. I started playing around just to see what this MailMerge "stuff" was all about. I don't have all the answers ... in fact I probably have more questions now.

I think that this procedure opens the Word template and creates a new document with fields from a record from the database that you reference. If you put the following statement at the bottom of your procedure:


I observed that the template disappears and only the new document remains. If you set your template up to Merge to the printer (rather create a new document), copies of your template will print ... one copy for each record.

The only problem I had was that the Access database (used as the DataSource) remained open after the procedure completed (and remained open even after I exited from Access. One thing is sure ... there more to this stuff than meets the eye.

Terry Waltz

patriciacardoza July 29th, 2004 11:36 AM


Terry is right. If you add objWord.Close to the end of the prodceure, you should see the results you're looking for. I do a lot with Word automation so post back with any other questions.

Patricia Cardoza
Outlook MVP

Lead Author, Access 2003 VBA Programmer's Reference

william.murray July 30th, 2004 07:59 AM

Hi Terry and Patricia - Thanks for the replies. I actually posted the same question to the access/vba forum and someone recommended using a reference to a word application instead of a word document and it works fine. I'm now in the process of trying to save the opened word document as an ole object into a table, which is then shown in a subform of the original form. Not to easy - I'm sure i'll be back to ask for help. Speak to you all later.


All times are GMT -4. The time now is 01:28 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.