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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't open database

Status
Not open for further replies.

sda7bobp

Technical User
Feb 14, 2005
28
0
0
US
Adapting some code I got here last week for another database (in which it is working well) I am having a problem opening an Access database to do a mailmerge in Word. The database that can't be open is the one that is calling the mail merge. Here is the code with the porblem area in red:
Code:
 Public Function MergeIt()
'------------------------------------------------------
'This code opens a Word template from Access, merges the
'data and prints the resultant documents
'------------------------------------------------------
Dim odoc As Word.Document, objWord As Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set odoc = objWord.Documents.Add("C:\Program Files\Microsoft Office\Templates\AccessSurgRpt.dot")
[COLOR=red] odoc.MailMerge.OpenDataSource _
Name:="C:\My Documents\Surgery & Analgesia Database.mdb", _
linktosource:=True, _
Connection:="QUERY qrySurgRpt", _
SQLStatement:="Select * FROM qrySurgRpt"[/color]
odoc.MailMerge.Execute
odoc.PrintOut
End Function

Any suggestions?
Bob
 
What exactly is occurring or not occurring, or what is the error if one is given?

One possibility is to try removing the SQLStatement line because I do not believe it is necessary with the Connection line you have provided.

Hope this helps,
Tom
 
Tom,
I removed that line and got the same error 5922 "Word was unable to open the database". Sorry I did not include that in the original post.
Bob
 
The database that can't be open is the one that is calling the mail merge
Hopefully this database is not open exclusive.
Which version and sp of word ?
What happens when you double-click AccessSurgRpt.dot in an Explorer window ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PH,
Word 97 SR2

What happens when you double-click AccessSurgRpt.dot in an Explorer window ?
--It opens to the template without merging the data, as I would expect. It does this through the code also. It gets that far and then the error message comes up. If I try to complete the merge from that point with the merge buttons on the mail merge toolbar, it merges as it should. The problem seems to be with the code.
 
If I try to complete the merge from that point with the merge buttons on the mail merge toolbar, it merges as it should
Play with the macrorecorder when doing that.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Play with the macrorecorder when doing that.

I'm sorry, I don't understand what you are asking me to do. Should I just eliminate the code that doesn't seem to work and complete the merge and printing manually? Or are you suggesting a macro from within Access to complete the task?
Bob
 
Hi,

I am having the exact same problem.

I got some code and adapted it for my own needs. it ran fine all the way through development but when it was user tested i got 5922. I think it has something to do with the fact that when the db is started, the db window, full menus etc are taken away....

Does this scenario ring any bells with you?

Did you find a solution? This problem is really causing me some stress, I can't see why it doesnt work.

Cheers

Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top