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

Opening a Word document from Access? 1

Status
Not open for further replies.

MrRecipe

Technical User
Sep 7, 2002
3
GB
I have written a simple database of recipes, the database stores author, type of recipe and main ingredients. The actual recipes themselves are stored as individual Word documents.

I want to be able to view a recipe on my database and have the option to click a button and have Access automatically search for the file and open the document in MS Word.

Each recipe has an "autonumber" primary key so I'm assuming that each WORD document will need to be saved with that unique reference for ease of reference and identification?

I'm guessing that I can do this via a command button and a Macro/VBA code but I really don;t know where to begin.

I am extremely new to this so any help would really be appreciated. Thank you
 
Hi

Using a hyperlink may do what you require, look in help under hyperlink for how to create a hyperlink to a word document and how to save a hyperlink in a table column, also there is an example of hyperlink usage in the Northwind sample database shipped with Access.

If you want to open the recipe document red only (to prevent user from changing maybe?) then you need to write some VBA code to create an instance of word and open the (word) file in code as a readonly document. You need to use CreateObject / GetObject (see help agin for info). You can saave the file path of each menu in the table of menus, and use that path to open the word document.

If you need more specific instructions post back.

Regards
Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
kenneth.reaySPAMNOT@talk21.com
remove upper case to use
 
Look at This Forums Experts and click on Oharab. He has an FAQ on this very subject Neil Berryman
IT Trainer
neil_berryman@btopenworld.com
 
Sorry it's taken me a while to get back to you guys - your advice is much appreciated but I am still stuck.

Ken, I can create a hyperlink and that works fine but as I have a different form for each recipe I've noted that whenever I change the hyperlink for a subsequent record it then changes to that hyperlink on every single record. I think you already knew that this would happen and therefore mentioned CreateObject/GetObject? I've looked these up and cannot find them?

If you could give me any extra help it would be much appreciated?

Neil, Thanks for your input too, I looked at the FAQ by Oharab and have pasted it into a general event on my form. Unfortunately I get an error and don;t have the skills to see what I am doing wrong, additionally he then makes reference to "calling" and this concept again, loses me.

I;m sorry to be a pain in the ar*e guys, can anybody help me accomplish this?
 
Have you got a field in the underlying table for your hyperlink?

I suspect that at present the field you are using on the form for your hyperlink is unbound, which means it will just hold whatever information you input and show it, as you say, on every reocrd. If you bind this box to a field in the underlying table, it will show the correct hyperlink as you page through the records.

HTH Nigel
Didn't someone say work is supposed to be fun? They didn't have computers then I guess....
 
It might be interesting for your to store the DOC files inside the MDB table. Normally, this would make your MDB explose, but there is a special wizard which avoids this and makes it very easy to integrate Word-Docs in Access.
 
All sorted, it was me being being a complete muppet.

I had added the hyperlink to the form without creating an entry on the table. All done.

Thanks for all your help - nice to see there is a community out there willing to pull together.
 
I've had better luck storing the path info for the docs in question in a text field, then using the CreateObject trip to make an instance of WinWord, and append the field holding the path to its .Documents property. Since you're already using an autonumber as the key, you can use sripting runtime to check for an instance of the file and createdir, etc based on the key (insures unique doc names).

Then...you can use a callback from your word doc (VBA6 rocks) to make a determintation on what to do with itself based on the name you may or may not have assigned...ie

Sub AutoOpen()

Dim objApp As Access.Application
Dim dbsThis As Database
Dim strDocName As String
Dim rstCurDoc As Recordset
If ActiveDocument.Name = "The_Template.doc" Then
Set objApp = GetObject(, "Access.Application")
Set dbsThis = objApp.CurrentDb
Set rstCurDoc = dbsThis.OpenRecordset("CURRENT")
strDocName = rstCurDoc.Fields(0)
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With

ActiveDocument.SaveAs strDocName
rstCurDoc.Close
Set dbsThis = Nothing
Set objApp = Nothing
Application.Quit NoSave
End If
End Sub

This only fires if it's a blank doc, otherwise it populates from the caller (MSAcc db) via word's native merge...kinda a twist, but it works slick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top