Opening an Excel file from Access form button

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

Guest

Dear Access experts,

I am working on a form and want to be able to open an Excel file from a form
button, but the Excel file to be opened will be based on a variable name that
the user types into a field. In other words, if the user types "A", and
clicks the button, the excel file workA.xls is open. If the user types "C"
and clicks the button, the excel file workC.xls is open. The files are in a
few different directories. What is the best method to do this? How do I
have Access open the Excel file? In addition, would a Select Case statement
be the best way to have the various files be chosen? Thanks in advance for
your input into this.

Neal
 
You can use that to open the excel file

Dim MyFileName as string
MyFileName = "C:\work" & Me.FieldName & ".xls"
application.FollowHyperlink MyFileName
 
Easiest way to open Excel would be to use the FollowHyperlink method:

FollowHyperlink "C:\My Document\MySheet.xls"

or, if the full path to the file is stored in a variable strPath,

FollowHyperlink strPath

A Select Case statement is probably appropriate to set strPath, but you
could also introduce the standard Windows Select File dialog, to let them
pick the file from anywhere on the machine (see
http://www.mvps.org/access/api/api0001.htm at "The Access Web" for a
complete example), or store the information in a listbox, rather than making
them type it.
 
Ofer,

Thanks for the reponse. I will try it out and make sure the file name is
the same as the field name. Would the hyperlink open the excel file
automatically?

Neal
 
Douglas,

Thanks for the suggestion. I will look up the reference on Select File
dialog to see how that works.

Neal
 
I have a similar request. I have a table that is linked to customers,
and within this tabe is a field that contains an absolute path to a
visio diagram. I'd like to have a button on my form that displays the
visio diagram when clicked (opening the external application is fine)
.... will the same code sample work, and if so, how do I set the
me.fieldname as a specific field attached to this client?

I think I would like the button to work as such:

open form
click button
button inquiry "What client number" -- three digit client number
execute visio with reference to file name

thanks in advance.
joey
 

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

Back
Top