How to open Microsoft Word documents from a Microsoft Access Form

G

Gary B

I have a Form (Sales Orders) which contains a Sales Order number field. The
number in this field is used as the Delivery Note number when an item is
Despatched to a Customer. E.g. Sales Order number = 123456, Delivery Note
Number = 123456

The Delivery Note is scanned and filed in the network when returned with the
Driver e.g. G:\Distribution\POD\123456.doc

I can open up a Word Doc using -> Application – Run MS Word Command Button
and input the file path but this only goes as far as the Folder e.g.
G:\Distribution\POD

I would like to be able to link to each unique scanned document from the
Sales Order number field in my form to the POD.

Thanks in anticipation
 
M

Mr B

Gary B,

If you are wanting to open the "scanned documents" then you would not be
opening a Word document. You would actually be opening a graphic file of some
type, depending on what file type the scanned image is being saved as.

To open or show the graphic you would need to have the entire path,
including the file name, saved to a field and the use that to open the
graphic.
 
G

Gary B

If it was a Word Document would I still have enter the entire path?

I'm trying to get a user to access a document that is stored outwith access
& maintained elsewhere. Each Form will have a different number in the Sales
order number field.

I can create a Folder and point the user to that folder with the Command
button below. There may be 200+ documents in that folder. They could scroll
through that folder and find the file manually.

I was hoping to get the filename picked up from the field within the
original Form, which has the same name as the file in the Folder outwith
access.
 
M

Mr B

I may not be understanding what you are asking, but to try to answer your
question:

If you want to open any file, you will have to know the entire path. That
path can be a default path (just a predefined folder) or it could be just any
folder.

From the way you describe how the document is being processed and saved, I'm
afraid you will have to know the folder and the filename that you want to
retrieve.

If I understand correctly, you will have the file name in a field on your
form. If this is true, then all you need is the folder and you could then
concatenate the path and the file name together to get the entire path.

Many times this type if thing is something that can be coordinated between
you and the persons who are actually saving the files. Just come up with a
specific folder where all relative files are to be stored. Then, if you have
the file name in your form, it is simple to check to be sure the file is
there and if so, open it.
 
G

Gary B

Thanks.

Yes the file name is in a field on the Form and the files are being saved to
a specific folder.

Can you let me know the best way to concatenate the path and the file name
together to get the entire path.

Thanks again
G
 
M

Mr B

Gary,

If the file name is in a textbox on your form, you can first define a string
type variable and then assign the path and file name to the string variable
like this:

dim strFulPathAndName as string

strFulPathAndName = "C:\Temp\" & me.NameOfYourTextbox

In the line above, you would replace the "C:\Temp\" with the actual path to
the folder where the files are being stored.

Then you can use the string type variable that will now hold the complete
path and the file name in your code to open the file.
 
G

Gary B

Mr B,

Put the code in as suggested but file didn't open:

dim strFulPathAndName as string

strFulPathAndName = "G:\Division\Wholesale Forecast\Load Plans\" &
me.LoadPlanNumber

Is ther anything obvious I have done wrong?

Gary
 
M

Mr B

Gary,

It may not be so obvious. I was assuming that you already had code that
would actually open the file and only need to know how to put the path and
filename together. Sorry about that.

Once you have the path and filename in the variable you can try to use
something like the code below to open the file. I may depend on the file
type you are trying to open. At any rate, uou can give it a try and see if
you can make it work.

Application.FollowHyperlink strFulPathAndName

This worked here to open a PDF type document. If the document type is
registered with Windows then it should work.
 
G

Gary B

Done the trick

Thanks
Gary

Mr B said:
Gary,

It may not be so obvious. I was assuming that you already had code that
would actually open the file and only need to know how to put the path and
filename together. Sorry about that.

Once you have the path and filename in the variable you can try to use
something like the code below to open the file. I may depend on the file
type you are trying to open. At any rate, uou can give it a try and see if
you can make it work.

Application.FollowHyperlink strFulPathAndName

This worked here to open a PDF type document. If the document type is
registered with Windows then it should work.

--
HTH

Mr B
draccess at askdoctoraccess.com
 

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