Opening MS Word in Access

K

Ken Curtis

I know that a Word document can not be opened by Access. This topic has been
discussed endlessly (and correctly so) in these discussion groups.

However, I have created a table (Forms) and pasted Word documents to it. In
Access (on an Access form) I have created a combo box that lists my Word
documents, and attached that to a bound object frame. By selecting a Word
document from the combo box I can "see" the Word document in the object
frame. This is great for previewing the Word documents.

BUT, surely there is a way to tell Access to open the Word document IN Word.
Can I have Access open Word - the program - and then have that program (Word)
open the document I am "seeing"?

This sound doable ... if thought through by one of you people who know what
you're doing (and, apparently, very well!).

Thanks
 
F

fredg

I know that a Word document can not be opened by Access. This topic has been
discussed endlessly (and correctly so) in these discussion groups.

However, I have created a table (Forms) and pasted Word documents to it. In
Access (on an Access form) I have created a combo box that lists my Word
documents, and attached that to a bound object frame. By selecting a Word
document from the combo box I can "see" the Word document in the object
frame. This is great for previewing the Word documents.

BUT, surely there is a way to tell Access to open the Word document IN Word.
Can I have Access open Word - the program - and then have that program (Word)
open the document I am "seeing"?

This sound doable ... if thought through by one of you people who know what
you're doing (and, apparently, very well!).

Thanks

You can code a command button click event:
Application.FollowHyperlink "C:\PathToFolder\MyDocName.doc"

If you include the DocName (as the first column) and the Path to the
document (as the second column) in the combo box rowsource, then you
could use code, in the Combo Box AfterUpdate event:

Application.FollowHyperlink Me.ComboName.Column(1)

As Combo boxes are zero based, Column(1) is the second column.
 
K

Ken Curtis

This is good, fredg. So, for the sake of clarity: by coding a single command
button on the form (in 'click event') to activate a hyperlink pointing to the
specific document showing on the form the Word document will open? Is this
correct ... or as correct as I need to know?

Regards
 
F

fredg

This is good, fredg. So, for the sake of clarity: by coding a single command
button on the form (in 'click event') to activate a hyperlink pointing to the
specific document showing on the form the Word document will open? Is this
correct ... or as correct as I need to know?

Regards

Yes, that is correct.
But, depending upon your set-up, you don't even need a command button.
Let's say you have a main table with each of the documents listed in
separate records in the [Document] field, i.e. "Solicitation.doc" or
"Marketing.doc" etc.
You then navigate to a record, and the "Solicitation.doc" is the value
in that records [Document] field.
Let's also say that ALL of the documents are stored in the same
folder, i.e. "C:\My Document Folder".

You could code the [Document] control's Double-click event:

Application.FollowHyperlink "C:\My Document Folder\" & Me![Document]

If the documents are stored in various different folders, then you
must include a field, let's call it [Path], that will contain that
folder's location, i.e. "C:\My Document Folder" or "E:\Sales Support"

Then you would code the [Document] Double-click event:
Application.FollowHyperlink Me![Path] & "\" & Me![Document]

Use the Double-click event, instead of the Click event, to prevent
inadvertent opening of the document.

A combo box is fine as well.
 
K

Ken Curtis

You are making it toooo easy, fredg! Yes!! All documents (320 of them!) are
stored in the same folder. So, I translate what you wrote here:

"Let's also say that ALL of the documents are stored in the same
folder, i.e. "C:\My Document Folder".
You could code the [Document] control's Double-click event:
Application.FollowHyperlink "C:\My Document Folder\" &
Me![Document]"

to mean this: I paste Application.FollowHyperlink "C:\My Document Folder\" &
Me![Document] into On Double-click in the button's properties, then, when
the button is doubleclicked, Access will know that the [Document] refered to
is the Word file I am looking at on the form, and will open that file.

Am I close?



--
Ken Curtis


fredg said:
This is good, fredg. So, for the sake of clarity: by coding a single command
button on the form (in 'click event') to activate a hyperlink pointing to the
specific document showing on the form the Word document will open? Is this
correct ... or as correct as I need to know?

Regards

Yes, that is correct.
But, depending upon your set-up, you don't even need a command button.
Let's say you have a main table with each of the documents listed in
separate records in the [Document] field, i.e. "Solicitation.doc" or
"Marketing.doc" etc.
You then navigate to a record, and the "Solicitation.doc" is the value
in that records [Document] field.
Let's also say that ALL of the documents are stored in the same
folder, i.e. "C:\My Document Folder".

You could code the [Document] control's Double-click event:

Application.FollowHyperlink "C:\My Document Folder\" & Me![Document]

If the documents are stored in various different folders, then you
must include a field, let's call it [Path], that will contain that
folder's location, i.e. "C:\My Document Folder" or "E:\Sales Support"

Then you would code the [Document] Double-click event:
Application.FollowHyperlink Me![Path] & "\" & Me![Document]

Use the Double-click event, instead of the Click event, to prevent
inadvertent opening of the document.

A combo box is fine as well.
 
F

fredg

You are making it toooo easy, fredg! Yes!! All documents (320 of them!) are
stored in the same folder. So, I translate what you wrote here:

"Let's also say that ALL of the documents are stored in the same
folder, i.e. "C:\My Document Folder".
You could code the [Document] control's Double-click event:
Application.FollowHyperlink "C:\My Document Folder\" &
Me![Document]"

to mean this: I paste Application.FollowHyperlink "C:\My Document Folder\" &
Me![Document] into On Double-click in the button's properties, then, when
the button is doubleclicked, Access will know that the [Document] refered to
is the Word file I am looking at on the form, and will open that file.

Am I close?

No. Not close at all. Maybe near.<g>
Here is how to enter code into an event.
In design View, select the control.
Click on the Event tab.
On the Double-click line write:
[Event Procedure]
The click on the little button with 3 dots that appears on that line.
When the VBA code window the cursor will be flashing between 2 already
existing lines of code.
Between those 2 lines write (on one line):

Application. FollowHyperlink "C:\My Document Folder\" &
Me![Document]

Exit the code window.
Run the form and try it. It should work.

Note: Change the path to your actual path, and change [Document] to
whatever the actual field name is that you are using.
 
K

Ken Curtis

Again, thanks, fredg (or who ever you may be behind that mask!). The
information regarding how to enter code correctly is unvaluable.
When you say, "and change [Document] to whatever the actual field name is
that you are using", you are refering to the field name in the data base
table that holds the forms I have imported for preview purposes, correct? Or
do I need to type in the individual names of each of the forms (320) of them
.... which seems not at all practical.
Thanks
--
Ken Curtis


fredg said:
You are making it toooo easy, fredg! Yes!! All documents (320 of them!) are
stored in the same folder. So, I translate what you wrote here:

"Let's also say that ALL of the documents are stored in the same
folder, i.e. "C:\My Document Folder".
You could code the [Document] control's Double-click event:
Application.FollowHyperlink "C:\My Document Folder\" &
Me![Document]"

to mean this: I paste Application.FollowHyperlink "C:\My Document Folder\" &
Me![Document] into On Double-click in the button's properties, then, when
the button is doubleclicked, Access will know that the [Document] refered to
is the Word file I am looking at on the form, and will open that file.

Am I close?

No. Not close at all. Maybe near.<g>
Here is how to enter code into an event.
In design View, select the control.
Click on the Event tab.
On the Double-click line write:
[Event Procedure]
The click on the little button with 3 dots that appears on that line.
When the VBA code window the cursor will be flashing between 2 already
existing lines of code.
Between those 2 lines write (on one line):

Application. FollowHyperlink "C:\My Document Folder\" &
Me![Document]

Exit the code window.
Run the form and try it. It should work.

Note: Change the path to your actual path, and change [Document] to
whatever the actual field name is that you are using.
 
F

fredg

Again, thanks, fredg (or who ever you may be behind that mask!). The
information regarding how to enter code correctly is unvaluable.
When you say, "and change [Document] to whatever the actual field name is
that you are using", you are refering to the field name in the data base
table that holds the forms I have imported for preview purposes, correct? Or
do I need to type in the individual names of each of the forms (320) of them
... which seems not at all practical.
Thanks

Usually, the name of a form control is the same as the name of the
field in it's control source property. So if the name of the field in
the table is "George" and you add this field to your form, Access will
name the control "George".
However, if you have added an unbound control to the form and then set
it's control source property to the "George" field, the name of this
control will be "TextANumber". Let's say "Text1".

I have no idea what your field is named, nor what the control is
named, so I used [Document] as a generalized name.

Change [Document] to what ever the actual name is of the control on
the form that displays the name of the document. It may be "Document",
it may be "George", it may be "Text1", etc., but whatever the name is,
that's what you use.
To find the control's name, display the form's Property sheet. Select
that control. Click on the Other tab. The control's name is the first
property on that tab.
 
K

Ken Curtis

Thank you, fredg. I'll try this first thing in the morning, and, assuming I
do it correctly (positive thinking, et al), I should be a very happy Canadian.
Thanks again.
Regards
--
Ken Curtis


fredg said:
Again, thanks, fredg (or who ever you may be behind that mask!). The
information regarding how to enter code correctly is unvaluable.
When you say, "and change [Document] to whatever the actual field name is
that you are using", you are refering to the field name in the data base
table that holds the forms I have imported for preview purposes, correct? Or
do I need to type in the individual names of each of the forms (320) of them
... which seems not at all practical.
Thanks

Usually, the name of a form control is the same as the name of the
field in it's control source property. So if the name of the field in
the table is "George" and you add this field to your form, Access will
name the control "George".
However, if you have added an unbound control to the form and then set
it's control source property to the "George" field, the name of this
control will be "TextANumber". Let's say "Text1".

I have no idea what your field is named, nor what the control is
named, so I used [Document] as a generalized name.

Change [Document] to what ever the actual name is of the control on
the form that displays the name of the document. It may be "Document",
it may be "George", it may be "Text1", etc., but whatever the name is,
that's what you use.
To find the control's name, display the form's Property sheet. Select
that control. Click on the Other tab. The control's name is the first
property on that tab.
 
C

Charlie Shaffer

fredg said:
You can code a command button click event:
Application.FollowHyperlink "C:\PathToFolder\MyDocName.doc"

If you include the DocName (as the first column) and the Path to the
document (as the second column) in the combo box rowsource, then you
could use code, in the Combo Box AfterUpdate event:

Application.FollowHyperlink Me.ComboName.Column(1)

As Combo boxes are zero based, Column(1) is the second column.
Fred, such a simple answer to my problem. I'm using Access 2007 and one of
the features I've started using is the Date Picker. I was having some
trouble closing the form with the unbound text box I was using to activate
the date picker. the date picker form opens a report with a date range
between <date picker> and Now(). I like to output my reports to Word and
leave them open to review them. However, closing the Access report and date
picker form always returned the focus to Access which is annoying. So here
is where your assistance helped me:

Update event of date picker text box:
DoCmd.OpenReport "MyAccessReport", acViewReport, , , acHidden
DoCmd.OutputTo acOutputReport, "MyAccessReport", acFormatRTF,
"C:\MyReportPath\MyReportName.doc", False
DoCmd.Close acReport, "MyAccessReport", acSaveNo
DoCmd.Close acForm, "DatePickerForm", acSaveNo
Application.FollowHyperlink "C:\MyReportPath\MyReportName.doc"

I get a quick notification that the report is being created and then MS Word
opens with my report right there for me. The reason I'm doing it this way is
so I can use the information in the DatePickerTXT box in the report header.
I'll code that later since I spent most of my day today trying to figure out
how to close the date picker and Access report and still end up looking at my
MS Word report. Thanks for helping Ken because in the end I got some help
too! ;-)

Charlie
 
A

alma mejia

Charlie Shaffer said:
Fred, such a simple answer to my problem. I'm using Access 2007 and one
of
the features I've started using is the Date Picker. I was having some
trouble closing the form with the unbound text box I was using to activate
the date picker. the date picker form opens a report with a date range
between <date picker> and Now(). I like to output my reports to Word and
leave them open to review them. However, closing the Access report and
date
picker form always returned the focus to Access which is annoying. So
here
is where your assistance helped me:

Update event of date picker text box:
DoCmd.OpenReport "MyAccessReport", acViewReport, , , acHidden
DoCmd.OutputTo acOutputReport, "MyAccessReport", acFormatRTF,
"C:\MyReportPath\MyReportName.doc", False
DoCmd.Close acReport, "MyAccessReport", acSaveNo
DoCmd.Close acForm, "DatePickerForm", acSaveNo
Application.FollowHyperlink "C:\MyReportPath\MyReportName.doc"

I get a quick notification that the report is being created and then MS
Word
opens with my report right there for me. The reason I'm doing it this way
is
so I can use the information in the DatePickerTXT box in the report
header.
I'll code that later since I spent most of my day today trying to figure
out
how to close the date picker and Access report and still end up looking at
my
MS Word report. Thanks for helping Ken because in the end I got some help
too! ;-)

Charlie
 

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