Run Application from Command Button

R

RobV

I have 2 databases that I would like to switch between by placing a Command
button on a form in each database, clicking on the button would open the non
active database. I placed a button and using the wizard entered the path to
the one database file as shown in the wizard eg. Access.exe C:\My
Documents\xyz.mdb
When I open the form and click on the button, I get a message box saying
"File Not Found".
I have very little experience in code, so any suggestions in plain English
or cut and past form would be greatly appreciated.
 
A

Arvin Meyer [MVP]

The easiest way is to use ShellExecute to open anything you want. The code
is here:

http://www.mvps.org/access/api/api0018.htm

Then your command button code would simply be:

Dim strCurPath As String
strCurPath = "C:\The path to file you want to open"
Call fHandleFile(strCurPath, WIN_NORMAL)
 
R

RobV

Thanks for the very quick response. I will try it and hopefully it will work
for me. I will let you know.
 
R

RobV

Thanks for the quick response. I tried placing the code in for the command
button that you sent. I entered the path to the database. Then when I tried
clicking the button I got a Compile error: Sub or Function not defined. With
the - Call fHandleFile - highlighted.
Is there something more I need to do?
 
D

Douglas J. Steele

You need to copy everything between Code Start and Code End from the URL
Arvin gave you into a new module (not a class module, nor a module
associated with a form or report). When you save the module, do not name it
the same as any of the routines in the module.

BTW, the answer to your original question was that because the path to the
database included a space, you needed to use quotes around it:

Shell "Access.exe ""C:\My Documents\xyz.mdb"""


--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)
 
R

RobV

Thank you. It now works as I want it to. I did try using the Command Button
with the "Access.exe""c:\My Documents\xyz.mdb""" set as the string, but again
I got file not found message. But as long as the other works I am happy.
 

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