Merge Access Form (current record) to Word Template

Posted on 2003-03-14
Medium Priority
Last Modified: 2008-04-01

I had this working the other day and now it just wont work right.

I have to merge a few fields from a form that has data entry in it.  Only a few of the fields get merged
i use a button to save the record and open the Merge Form and then use a query to give me just those fields with =Forms!QrySIDRecord!ValidationNumber in the criteria of the Unique ID of the query.  That returns the current record on the Merge Form.  And then word opens the template but wont merge and stops at the OpenDataSource if I change anything then the QrySIDRecord doesnt work and I cant return the current record to the form.

Does anyone have any ideas?

Dim objWord As Word.Application
Dim doc As Word.Document

Set objWord = CreateObject("word.application") 'Create an instance of Word
objWord.Visible = True 'Make sure you can see it!!
objWord.WindowState = wdWindowStateMaximize 'Maximize it, otherwise is always about 1/4 of screen

'Open a document based on a template for merging
objWord.Application.Documents.Add Template:="C:\Documents and Settings\XXXX.XXX-XX\Desktop\RecordVrs2_03122003.dot", NewTemplate:=False

'Store name of document for later use
varDocName = objWord.ActiveDocument.Name

objWord.ActiveDocument.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\XXXXX.XXX-XXX\Desktop\QID.mdb", _
LinkToSource:=True, _
Connection:="QUERY QrySIDRecord", _
SQLStatement:="Select * from [QrySIDRecord]"

If Err.Number = 94 Then
                objWord.Selection.Text = ""
                Resume Next
            End If

End Sub

The error is this line: objWord.ActiveDocument.MailMerge.OpenDataSource

and the error message is this: Run-Time error '-2147417851 (80010105)'
Automation error
The server threw an exception



Question by:stokh
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

Accepted Solution

boomstam earned 500 total points
ID: 8139300

it seems to me you have 2 options in the OpenDataSource mixed up.
1) Use the Connection part to define a ODBC connection, and combine this with the SQLStatement part to define the records to select.
2) Use the Connection part to point to a Query from your MDB file. In this case you don't use the SQLStatement part.

Just define a QUERY "QrySIDRecord" in the MDB file using "Select * from [QrySIDRecord]"
and then call:
objWord.ActiveDocument.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\XXXXX.XXX-XXX\Desktop\QID.mdb", _
LinkToSource:=True, _
Connection:="QUERY QrySIDRecord"

LVL 12

Expert Comment

ID: 8785729
Hi stokh,
This question has been abandoned and needs to be finalized (101 days since last comment).

   You can accept an answer, split the points, or get a refund. Go to
   http://www.cityofangels.com/Experts/Closing.htm for information and options.


EE Cleanup Volunteer for Microsoft Access

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

777 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