Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Mail Merge from Access 1

Status
Not open for further replies.

LarryDeLaruelle

Technical User
May 19, 2000
1,055
US
I am trying to set up a mail merge function in Access '97 (as described in MS Document Q159328) and it runs OK up to a point:<br><br>a new instance of Access is opened (which is another problem for another day);<br><br>Word opens;<br><br>then I get a run time error (5992) &quot;Word was unable to open the data source&quot;.<br><br>Here is the code (pretty much as I picked it up from the MS doc):<br><br>Public Function Mergeit(strOaklawn As String)<br><br>Dim objWord As Word.Document<br>Set objWord = GetObject(&quot;C:\WordForms\DisSum.dot&quot;, &quot;Word.Document&quot;)<br><br>' Make Visible<br>objWord.Application.Visible = True<br><br>' Set the mail merge data source<br>objWord.MailMerge.OpenDataSource _<br>Name:=&quot;G:\database\TCC Reports\TCCReports.mdb&quot;, _<br>linktosource:=True, _<br>Connection:=&quot;QUERY qbeWordForm1&quot;, _<br>sqlstatement:=&quot;SELECT * FROM [qbeWordForm1] WHERE [OaklawnNum] = '&quot; & strOaklawn & &quot;' ;&quot;<br><br>' Execute the Mail Merge<br>objWord.MailMerge.Execute<br><br>End Function<br><br>I tried the Help button when I got the run time error and was politely informed that the &quot;Topic does not exist&quot;.<br><br>When I click on debug, it highlights the entire .OpenDataSource line with the yellow arrow pointing at the last line (the SQL statement).<br><br>My guess is that something is not right with the SQL statement but I am at a loss to figure out just what that might be.<br><br>My undieing gratitude to anyone who can set me on the path to enlightenment.<br><br><br><br>
 
I copied your function and will paste it in Access it to see whats up.<br>As for Word Opening Access that's a given cause that's the way it was written. I presume you are using Access for more than just a place to store address for Word mail merge.<br>I've done the same thing slightly differntly.<br>Put a button on an Access form that opens Word and merges the data at the same time.<br>The form of course is where you are making change's to the data for the mail merge. That way you already have Access open and it won't launch Access again<br>The Word merged data source could be a quey so it would return just the records you needed.<br>I create a macro in Word that Merged, Printed, and closed Word. <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
Try this:<br>&nbsp;&nbsp;&nbsp;&nbsp;Dim objWord As Object<br>&nbsp;&nbsp;&nbsp;&nbsp;Set objWord = GetObject(, &quot;Word.application&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;Set objWord = GetObject(&quot;C:\WordForms\DisSum.dot&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;' Make Visible<br>&nbsp;&nbsp;&nbsp;&nbsp;objWord.Application.Visible = True<br><br>I got it to work.<br>I don't have your data so can't check that<br><br><br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
Thanks for the reply, Doug.&nbsp;&nbsp;I have the merge working OK from within Word but because of the number of documents to be merged I would like to do it via Access.<br><br>I probably should have included some background with my question.&nbsp;&nbsp;I work for a Residential Treatment Center for disturbed and abused children.&nbsp;&nbsp;On admission a number of clinical forms (with basic identifier data) are created and stored in a network folder for that child.&nbsp;&nbsp;That folder is then available to the therapist to add case notes, etc.&nbsp;&nbsp;There are a total of 18 documents in this set (with more to be created); some are related to admission, some to on-going service and some to discharge.<br><br>What I would like to do is to set up an Access form with a combo box to select the name of the new admission and check boxes to identify the specific forms to be created.&nbsp;&nbsp;Access/Word would then merge the identifier info into each form and save them (Admission Name + Document Type = FileName) to the folder.&nbsp;&nbsp;This same scenario would be created for on-going service forms and discharge forms.<br><br>Our Admissions Clerk is very happy with the Merge routine I have set up now, but it is cumbersome and slow because she must open each document, modify the selection criteria, merge, save and close.&nbsp;&nbsp;From what I have seen so far, I know that doing this via Access may be at least as slow, but it would avoid the repetition and eliminate possible entry errors..<br><br>I hope this makes my problem a little clearer at least in terms of why I am trying to do it this way.<br><br>Thanks. <p>Larry De Laruelle<br><a href=mailto:larry1de@yahoo.com>larry1de@yahoo.com</a><br><a href= > </a><br>
 
I made an Access based Quoting System that had 6 word docs but the principle is the same.<br><br>1st Create a form that has all of the data on it for each Word doc. Or create several forms that have most of the data for several Similar Word Docs.<br><br>Next have the Word Docs look at Access Queries Not tables.<br>Those Queries then look at the particular Forms for their Input instead of prompting. So In word when the Documnt is opened it is looking at a query which is looking at a form.<br>No fiddling is done in Word to get a specific record or records the Access quieries handle that.<br>OK<br>Now on your form you have several buttons or a Combo box that when clicked it launches a specific Word Doc.<br>You could also make a Macro in Word that printed the document.<br>So the call to Word would open a particualr doc, Print it out then close and be back in Access ready for the next one.<br><br><br><br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
Hello Larry!

I was just curious if you ever got this working? I'm trying something similar, with Access 2000, and it works great except that every time I run the merge, I get a message saying

&quot;The database has been placed in a state by user 'Admin' on machine 'Erin' that prevents it from being opened or locked.&quot;

Wondered if you ran into this problem at all, and also if you ever managed to work around the second instance of Access opening?

I have basically the same code as you show above...

Set objWord = GetObject(&quot;C:\My Documents\N-K Properties\Super Suds\refundLetter.doc&quot;, &quot;Word.Document&quot;)

strCriteria = &quot;[letterNeeded] = 'Yes'&quot;
Set rst = CurrentDb.OpenRecordset(&quot;refund_info&quot;, dbOpenDynaset)
rst.FindFirst strCriteria
If rst.NoMatch Then
MsgBox (&quot;No letters found to generate.&quot;)
Else
' Make Word visible.
objWord.Application.Visible = True

objWord.MailMerge.OpenDataSource _
name:=&quot;C:\Windows\Desktop\CarWash Refunds.mdb&quot;, _
LinkToSource:=True, _
Connection:=&quot;QUERY refundLetterQry&quot;
'Execute the mail merge.
objWord.MailMerge.Execute

End If

I've tried setting permissions differently under Tools-Security, but still am getting message. Any ideas would be greatly appreciated!

Thanks, Janel
 
Jane:

I was under a time constraint so I just set it up do do the merge from Word. Works OK that way. Never did resolve this issue. Larry De Laruelle
ldelaruelle@familychildrenscenter.org

 
anasazii,

just for info, (i assume it's a long dead question but...)

I had exactly the same error coming up,

it was me altering the database in some way which meant I had the database opened exclusively. It took me ages to work out that even just clicking save on the toolbar converted the database to exclusive mode (i think???), meaning no-one else, and no other program could get access to it or the data in it.

I got round the problem of copying the data across into a second database and linking to that, certainly whilst I was developing the mail merge
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top