How to open Word Document from Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have some department forms that I would like to be able to print from a button on my Access 2000 switchboard. How is that done if it is possible?

Thanks

Dan Dickover
 
Usually, you can do it through ActiveX Automation:

1. InVBA Editor, click "Tools->References..." and check Word Object Library
(9.0 for Word 2K, 10.0 for XP...)
2. Place following code in a Button_Click procedure (Not tested, thorugh)

Private Sub OpenWordDoc(fileName As String)

Dim wdApp As Word.Application
Dim doc As Word.Document

Set wdApp=New Word.Application
wdApp.Visible=True

Set doc=wdApp.Documents.Open(fileName)

'You can edit the document programmtically here, such as placing data
from database to the document

doc.PrintOut

doc.Close False 'If you want to save changes made to the doc, then
doc.Close True
wdApp.Quit

End Sub

Do some study ob Word's object model, you will find that you could do almost
everything programmingly to Word as a human user does.

Daniel Dickover said:
I have some department forms that I would like to be able to print from a
button on my Access 2000 switchboard. How is that done if it is possible?
 
Dear Albert,

thank you very much for your solution. I searched the net for days for this.
Until now for no result. You should sell this solution to ms, since most
solution-providers offer solutions that are overfreighted and with little to
no use for me (and others) and the small solution I (we) need. I don't
understand why ms hasn't long since integrated something like your solution
into access. I was angry like hell that the prog itself doesn't provide the
possibility to hand over only the active or marked record to Word but only
all records of one table or form. Or does it? I couldn't find a way. Even a
selection of one record didn't help. I don't need massmailing funktion. I
and many users need an easy to use function to write a personal letter to
one of many clients. With Outlook it's possible to hand over just one record
to word, and that's exactly what i need, but I need many custom fields and a
solution (e.g. Outlook DataLink by TeamScope) to connect all Outlook fields
(including the custom fields) with an access-table costs 700$ extra.
Your solution is not exactly what i searched for but nearly. Is it possible
to change your makro, so that it stops before the merging to the new doc
beginns? I need the possibility to insert further text blocks with
integrated mergefields before i use a recorded macro to start the merging to
the new (simple) doc, what is just the same what the built in form letter
function does, with the only difference, that the database that is handed
over to word consists only of the selected (marked active) record.

Thanks again.
Best regards
Torsten Teschner, Berlin, Germany
 
Torsten Teschner said:
Dear Albert,

thank you very much for your solution.

You are most welcome.
You should sell this solution to ms, since most
solution-providers offer solutions that are overfreighted and with little to
no use for me (and others) and the small solution I (we) need. I don't
understand why ms hasn't long since integrated something like your solution
into access.

Actually, I do strongly believe that how my merge code works should in fact
be part of ms-access. I simply released my code example because I felt very
strongly that my solution is how ms-access should have worked in the first
place.
I was angry like hell that the prog itself doesn't provide the
possibility to hand over only the active or marked record to Word but only
all records of one table or form.

Well, you can with my solution! The great thing about ms-access is there is
an incredible amount of free and open code on the web that you can grab to
do all kinds of interesting things. However, to answer you question...no,
ms-access does not have a single record to word merge built in. However,
many people like me have posted and provided solutions to the general public
anyway.
Is it possible
to change your makro, so that it stops before the merging to the new doc
beginns? I need the possibility to insert further text blocks with
integrated mergefields

Actually, there is a number of ways to do this. However, it is not clear
where those "text blocks" are going to come from? Do you have some un-bound
text boxes on the screen?

If you wish, based on your suggestion I will added the ability for users to
"insert" additional fields that don't necessary exists on the record
*before* the merge occurs. I can certainly add this feature...but I am not
sure it will solve/help you? Until I know where, or how the "extra text"
blocks come from..then adding this new feature might not help.

However, if you are saying that some code or functions you have generates
these text blocks..then I can certainly add a "feature" that lets you add
additional text fields BEFORE the merge occurs.

I guess I am asking how did/do you plan to select these extra text blocks?
 
Is it possible
Actually, there is a number of ways to do this. However, it is not clear
where those "text blocks" are going to come from? Do you have some un-bound
text boxes on the screen?

If you wish, based on your suggestion I will added the ability for users to
"insert" additional fields that don't necessary exists on the record
*before* the merge occurs. I can certainly add this feature...but I am not
sure it will solve/help you? Until I know where, or how the "extra text"
blocks come from..then adding this new feature might not help.

However, if you are saying that some code or functions you have generates
these text blocks..then I can certainly add a "feature" that lets you add
additional text fields BEFORE the merge occurs.

I guess I am asking how did/do you plan to select these extra text blocks?

Thanks for your answer Albert. I just want to add text (word-docs)
over the word-funktion - insert - file -. These are little
word-documents i have allready created with mergefields that
correspond to allready existing fields in the access-table. So with
your solution i could first load the letterhead, than the makro stops
and then i can insert text with the addressfields of my clients or
their insurance or their opponents or their lawyer or the court. And
following the adresstext i want to insert other textblocks that vary,
depending on the case, with information of the client, the file, the
opponent, the court. All information is in the allready existing
accesstable.

My accesstable has in every record addressdata for the whole file.
First field Filenumber, next field name of the file, e.g. "Mueller vs.
Schultz" next fields addressdata of the client Mueller, next fields
adressdata of the opponent Schultz, next fields special data of the
case, e.g. date of accident, insuranceno. of opponent, licenceplateno.
of opponent, and so on.

Thanks for your advice.

Yours sincerly
Torsten Teschner
 
Back
Top