Opening a Word document from Access

S

Stanley

I am using Office 2002 and I would like to open a Word document from Access.
My coding looks like this:

Private Sub cmdPreview_Click()
Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")
objWord.Documents.Open ("\\Zoniserver2\ZoniShared2\Wordstuff\Mydoc.doc")
objWord.Documents(1).Activate
End Sub

On the first click nothing displays, but in the directory the document has
its locking file open.
On the second click the document opens, but with a warning that it is read
only.
How can I get the document to open on the first click without any messages.
Thanks,
Stanley
 
J

Jack Leach

If you just want to open the document and don't require programming the
document with Automation, you can use Shell(), the ShellExecute API found at
mvps.org/access (my preferred), or Application.Followhyperlink

I don't know automation that well, but I think it may not be a good idea to
create the object in such a fashion and then exit the sub without closing the
object. This has a tendancy to leave instances of the object floating
around, and that's never a good thing. Generally this method is used when
the user wants to programmatically alter the document, and the file is saved
and closed through the auotmation, followed by closing the object itself.

hth

--
Jack Leach
www.tristatemachine.com

"I haven't failed, I've found ten thousand ways that don't work."
-Thomas Edison (1847-1931)
 
F

fredg

I am using Office 2002 and I would like to open a Word document from Access.
My coding looks like this:

Private Sub cmdPreview_Click()
Dim objWord As Word.Application
Set objWord = CreateObject("Word.Application")
objWord.Documents.Open ("\\Zoniserver2\ZoniShared2\Wordstuff\Mydoc.doc")
objWord.Documents(1).Activate
End Sub

On the first click nothing displays, but in the directory the document has
its locking file open.
On the second click the document opens, but with a warning that it is read
only.
How can I get the document to open on the first click without any messages.
Thanks,
Stanley

If you just wish to open the Word document, all you need is

Application.FollowHyperlink "Path to Folder\DocName.doc"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top