Open New Word Document from a Template Using a Command Button

T

TinaR

I'd like to open a new word document from a template on my network by
clicking on a Command button on my form. Is this possible? I'm using Access
and Word 2007.

Thanks,
Tina
 
M

Mark Andrews

You could use albert Kahall word merge code or get a copy of our product:
http://www.rptsoftware.com/products/email/

It's the best way I have found to do word merging from an Access database.
You control the directory where you store the word docs/templates and Access
can automatically do word merges based on how you set things up.

My product extends this concept to email templates (txt or html) and also
has some nice functions for batch report creation. Good when designing an
automated email with report attachment.

Mark
RPT Software
http://www.rptsoftware.com
 
T

TinaR

Thanks but I wasn't looking for software and I don't want to mail merge. I
want to open a word document from a template. I can use the hyperlink
address in the Command button's properties but that opens the template
instead of a new word document. What I was really looking for is some help
on coding. I know there's a way to do this in VB or perhaps using the
OnClick Event of the command button. I just need a place to start.

Tina
 
T

TinaR

Julie,

I thought I responded but for some reason my post never showed up....I used
your code below and it works except that it does open the template itself and
I need for the code to open a new instance of the the word document. If
anyone else can tell me how to do that, I would greatly appreciate it!

Thanks in advance.
Tina
 
T

TinaR

This works great! Thank you so much.

Now I would like to do the same thing for an Excel Template. I get an error
message in this line of code that you fixed:

eSet doc = oApp.Documents.Add(strDocName)

Since now I'm working with an Excel Spreadsheet instead of a Word Document,
I did change the one line of code to:

Set oApp = CreateObject("Excel.Application")

but I get an error message. Should I be changing something else too?

Thanks for all your help!



jubiiab via AccessMonster.com said:
It looks as the same code as before but I have changed this:

Set doc = oApp.Documents.Open(strDocName)

'to

Set doc = oApp.Documents.Add(strDocName)

'It works with access 2003 and word 2003
Hi Tina

I think I made it - try this and please tell me if it worked:

Private Sub cmdWord_Click()
On Error GoTo Err_cmdWord_Click

Dim oApp As Object
Dim doc As Object
Dim strDocName As String

Set oApp = CreateObject("Word.Application")
oApp.Visible = True

'change path
strDocName = "C:\testNy.dot"
Set doc = oApp.Documents.Add(strDocName)
Exit_cmdWord_Click:
Exit Sub
[quoted text clipped - 11 lines]
Thanks,
Tina
 
T

TinaR

This is great! Thank you so much!!


jubiiab via AccessMonster.com said:
With Excel template you do this:

Private Sub cmdExcel_Click()
On Error GoTo Err_cmdExcel_Click

Dim oApp As Object
Dim doc As Object
Dim strDocName As String

Set oApp = CreateObject("Excel.Application")
oApp.Visible = True

'Change path
strDocName = "C:\TestExcel.xlt"
Set doc = oApp.Workbooks.Open(strDocName)
Exit_cmdWord_Click:
Exit Sub

Err_cmdExcel_Click:
MsgBox Err.Description
Resume Exit_cmdWord_Click


End Sub
This works great! Thank you so much.

Now I would like to do the same thing for an Excel Template. I get an error
message in this line of code that you fixed:

eSet doc = oApp.Documents.Add(strDocName)

Since now I'm working with an Excel Spreadsheet instead of a Word Document,
I did change the one line of code to:

Set oApp = CreateObject("Excel.Application")

but I get an error message. Should I be changing something else too?

Thanks for all your help!
It looks as the same code as before but I have changed this:
[quoted text clipped - 31 lines]
Thanks,
Tina
 

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