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

Storing Word Templates in Access Database.

Status
Not open for further replies.

johnobrien

Programmer
Dec 6, 2002
4
GB
I have created an Access database with an OLE field to store Word Templates.

What I would like to do now is allow the user to select a template and open a new document based on that template.

I have the VB code to create a new document based on a template if it is stored on the users hard drive. Can anyone give me any tips on how to get the template from the database to the hard drive.

Thanks in advance.

John.
 
To be blunt - why bother with the OLE field?

Why don't you just include a combobox or a listbox with the template names and then add code to crank up your Word object and open a document based on the template according to the one chosen by your user?

For example:

'suppose they chose to open a document based on a letter template from a listbox called lstNames, stored in their standard Windows templates folder (C:\Program Files\Microsoft Office\Templates)

'also ensure that you have spelt the template name correctly in the listbox

Private Sub lstName_Click()

On Error GoTo AppError:

'dim a new word object
Dim appWd As Word.Application
Dim myDoc As Document


'open Winword
Set appWd = GetObject(, "Word.Application")


'show winword
appWd.Visible = True

'get document
Set myDoc = Documents.add Template:= _
"C:\Program Files\Microsoft Office\Templates\" & lstNames & ".dot", NewTemplate:=False


'make "live"
myDoc.Activate

'error handler
AppError:

If Err.Number = 429 Then 'no instance of Word open
Set appWd = CreateObject("Word.Application")
Resume
Else
msgbox err.description
err.clear
Resume Next
End If

End Sub

This is all pretty much from the top of my head and is therefore untested, but hope it helps.......


Asjeff
 
Thanks for the response.

I am looking to store the templates in a central repository, to ensure that the most up to date version is used.

I was thinking along the lines you suggested, but rather than get the template from the users PC, pick it up from a central server.
 
Yeah I have trouble here with my users not updating their templates when they should and then trying to blame me for it.

The only issue with server based templates is (as I'm sure you know - I'm not trying to teach you to suck eggs here) is that if the Network goes down no-one can use them.

You can substitute the local path above with a UNC path if you want to store the templates on a server

Asjeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top