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!

How do open a MS Word document in ACCESS.

Status
Not open for further replies.

kjspear

Programmer
Feb 13, 2002
173
US
Hello everyone,

I have a question about opening a Word XP document from ACCESS 2002 or XP. Basically what I have is quite simple. On a form I have a command button that I set up a Query make table. What I would like to do is when the user presses the button on this Access form, a Word document let's call it 'Letters.doc', opens and does a mail merge with a table in Access. I already have the merge set up once this document is opened. I need to know how I could get it opened via command button on the Access form? The idea is the prevent the user from trying to figure out how to filter the queries.

Thanks,
KJ
 
Hi

I use this to open pdf's in whatever default app is set for them:

strFileName = "Filename.pdf"
Application.FollowHyperlink strFileName, , True

Might do the trick for you.
 
I wrote a FAQ to use some code that does pretty much exactly what you want:

'Native' mailmerge reports - as painless as possible faq181-5088

Also, I respond to FAQ comments, so feel free to ask questions that way.
 
Hello,

The previous code from yetanotherjo gave me an error for some reason. I'm not sure if I missed something. The user presses a command button not a hyperlink, if that matters. I read the FAQ from pseale. It's great. That's something I will look into down the read. But right now I simply need to open this Word document when the user presses the button. I'm using Query Create Table. A table is created based on the query. I have Word already to do the merge once the document is opened. All the user has to do then is print it.

Any assistance would be apreciated.

Thanks
KJ
 
If all you need to do is open the Word document, then use the SHELL command. Something like:
Code:
    strDocName = "Full path to your Word document"
    strAppName = "C:\Program Files\Microsoft Office\Office10\Word.exe " & strDocName
    
    Call Shell(strAppName, 1)

You would add this code after your existing code for your command button.

See the Access Helpfile topic Shell Function
for more details on the Shell function.

However, if you actually need to control what happens in the Word document from Access, consider using Office Automation. For more on this topic, start with Understanding Automation in the Access helpfile.

HTH
Lightning
 
Hiya kjspear - You should be able to run that code as part of the on-click event for your button. Don't forget you need to tell it the entire path to your document. (I am right in assuming you have a specific document you open??). The only warning I get is a security thing about hyperlink.
 
Hello everyone:

Thank you for your responses. I found the following code on my own;

Example 1: Run a Macro in an External Microsoft Word 2000 Document
1. Start Microsoft Access and open any database or project.
2. In the Database window, click Modules, and then click New.
3. On the Tools menu, click References.
4. Click Microsoft Word 9.0 Object Library in the Available References box, and then click OK.
5. Type or paste the following procedure in the module:Function RunWordMacro()
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Set WordApp = CreateObject("Word.Application")
Set WordDoc = WordApp.Documents.Open _
("C:\Wordtest.doc")
WordApp.Visible = True
WordApp.Run "Macro1"

' Uncomment the next line of code to print the document.
' WordDoc.PrintOut Background:=False

' Uncomment the next line of code to save the modified document.
' WordDoc.Save

WordApp.Quit SaveChanges:=wdDoNotSaveChanges
Set WordApp = Nothing
End Function


The only difference is that I placed this code in the onclick event of a command button on my form.

It does exactly what I need it to do.

The web address is :
I thought that I would share this with you.

Thanks
KJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top