how to open a word document from within access? (1 Viewer)

wcoast

Registered User.
Local time
Today, 03:22
Joined
Jul 9, 2006
Messages
27
Hi!
I've done a report in Microsoft Word, that looks up data in Access database.
I would like to open the word document from within a form in Access (through a button click ).

If possible, i would also like to send word a filter, but that is not that important.

So, how do I accomplish opening a word document from a form in Access?

Thanks for your help,
/wcoast
 

elbweb

Self Taught Hero
Local time
Yesterday, 22:22
Joined
Jul 28, 2006
Messages
126
here is some code i got off the web that should help you:
Code:
Sub OpenWordDoc()
'In order to use this code you must set a reference to the
'Word object library by doing this. In the VB Editor click
'Tools, References. Then search for Microsoft Word n.n Object Library
'where n.n will depend on your version of Word.

Dim wdApp As Word.Application, wdDoc As Word.Document

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'Word isn't already running
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0

Set wdDoc = wdApp.Documents.Open("C:\temp\anyolddoc.doc")

wdApp.Visible = True

'You can now do whatever you like with the Word document e.g.

wdDoc.PrintOut
wdDoc.SaveAs "C:\temp\hello.doc"
wdDoc.Activate
'etc

End Sub

also, you should be able to just create a hyperlink to the word document if all you want to do is open it.
 

wcoast

Registered User.
Local time
Today, 03:22
Joined
Jul 9, 2006
Messages
27
Thanks elbweb!
The code you so nicely presented, worked just fine.
You saved me lots of time,
cheers ;)
 

elbweb

Self Taught Hero
Local time
Yesterday, 22:22
Joined
Jul 28, 2006
Messages
126
yup, and as for the filtering you talked about, a great part about anything in excel or word is the record macros feature, if you want to know how to script something, you turn on recording, do it, and then it gives you the code to reenact the same things, so you could use that to find the code for what you want to do, and then append it to the previous code to take one less step away :)
 

Users who are viewing this thread

Top Bottom