Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Merge Access Form (current record) to Word Template

Posted on 2003-03-14
2
Medium Priority
?
523 Views
Last Modified: 2008-04-01
Argh!  

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

Thanks

Stokh




   
0
Comment
Question by:stokh
2 Comments
 

Accepted Solution

by:
boomstam earned 500 total points
ID: 8139300
Stokh,

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"



0
 
LVL 12

Expert Comment

by:nexusnation
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.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

nexusnation
EE Cleanup Volunteer for Microsoft Access
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

578 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