Creating a command button to open a file

theresamwest

New member
Local time
Yesterday, 19:55
Joined
May 18, 2006
Messages
2
I have set up a database that houses file locations. The form that I have made shows a job # and the files that correlate with it. I would like to set up a command button that will read the file name and open it in Excell. If any one know how to do this I would greatly appreciate the help.
 
Hello:
Put the below code under a command button called cmdExcel: This will open Excel and open the file stated in the procedure. If you want to pick a file from an Access list box, set strXls to the selected listbox entry. Be sure to include full path name to the file. Also, in Access be sure your references are set to The Microsoft Excel 10.0 Object Library or whatever version your using.
'
Private Sub cmdExcel_Click()
'Launch Excel
Dim appExcel As Excel.Application, strXls As String
Set appExcel = CreateObject("Excel.Application")
MsgBox "Excel is running"
appExcel.Visible = True
'
'Open files here
strXls ="Your Filename complete with path goes here in quotes"
appExcel.Workbooks.Open (strXls)
Set appExcel = Nothing
End Sub

Regards
Mark
 
Thanks, Mark. It works great. I would like to know if there are any courses that you would recommend to futher my knowledge of Access.
 
Take a look at this forum. I learned a lot here. Also search the forum for recommended reading.
 

Users who are viewing this thread

Back
Top Bottom