Open Word File from Access

  • Thread starter Thread starter Brian Bennett
  • Start date Start date
B

Brian Bennett

Is there any way I can have a control button on an Access Project Database
Form open an MSWord file using the Project Number on the Form?
Thanks,
Brian
 
Dear Brian:

You must construct a command line. You can test this using Start/Run using
the Start button at the lower left of the screen.

On my system, MSWord is located at:

"C:\Program Files\Microsoft Office\Office10\WINWORD.EXE"

Yours may be different. You can use the Browse feature of Start/Run to
check this, or you can search for WINWORD.EXE using Windows Explorer.

Since the path may contain spaces, as mine does, enclosing the whole thing
in double quotes is mandatory. When constructing this in code, the string
itself is specified using a double quote. Creating a double quote within a
string requires you to add two consecutive double quotes at the point where
you want to place a double quote within the string. So, the above would be
coded something like this:

"""C:\Program Files\Microsoft Office\Office10\WINWORD.EXE"""

This can be submitted as a command line. But it does not yet contain the
name of the document you want opened. You must add that, including the path
to the document. It would look like this:

"""C:\Program Files\Microsoft Office\Office10\WINWORD.EXE"" ""C:\Documents
and Settings\Administrator\My Documents\MyDocument.doc"""

Now, we're almost there. You have to execute this "command line." There is
a library function to do this for you.

Shell ("""C:\Program Files\Microsoft Office\Office10\WINWORD.EXE""
""C:\Documents and Settings\Administrator\My Documents\MyDocument.doc""")

That will do it. There is an optional parameter to Shell that allows you to
control whether it is minimized, maximized, etc. See online help for those
details.

Tom Ellison
 
Back
Top