Opening another Access DB from a Form Button

S

Steve Stad

How can I open another access DB (eg., Database2) from a form in database1.
I think it would be easier to open a separate db (eg., Database2) vs
importing all of the queries, forms, reports into database1. I tried the
'run app' from a wizard. It builds this code - but I get error 'Invalid
procedure'. Also tried runApp in macro but get msg saying 'can not invoke
application using Run App action. Invalid path or component missing. I know
the path is correct - can you tell me what is missing?

Private Sub OpenCompletenessRep_Click()
On Error GoTo Err_OpenCompletenessRep_Click
Dim stAppName As String
stAppName = "G:\Tma\OCIO
Shared\C-WIP2-BU\DHIMS-BU\CompletenessDB_DHIMS_2010-04-15.mdb"
Call Shell(stAppName, 1)
Exit_OpenCompletenessRep_Click:
Exit Sub
Err_OpenCompletenessRep_Click:
MsgBox Err.Description
Resume Exit_OpenCompletenessRep_Click
end Sub
 
D

Dirk Goldgar

Steve Stad said:
How can I open another access DB (eg., Database2) from a form in
database1.
I think it would be easier to open a separate db (eg., Database2) vs
importing all of the queries, forms, reports into database1. I tried the
'run app' from a wizard. It builds this code - but I get error 'Invalid
procedure'. Also tried runApp in macro but get msg saying 'can not invoke
application using Run App action. Invalid path or component missing. I
know
the path is correct - can you tell me what is missing?

Private Sub OpenCompletenessRep_Click()
On Error GoTo Err_OpenCompletenessRep_Click
Dim stAppName As String
stAppName = "G:\Tma\OCIO
Shared\C-WIP2-BU\DHIMS-BU\CompletenessDB_DHIMS_2010-04-15.mdb"
Call Shell(stAppName, 1)
Exit_OpenCompletenessRep_Click:
Exit Sub
Err_OpenCompletenessRep_Click:
MsgBox Err.Description
Resume Exit_OpenCompletenessRep_Click
end Sub


An Access database is not an application, from the operating system's point
of view, but rather a document. What you need to do is shell to the
msaccess executable, passing the database path & name on the command line.
You also usually need to use quotes in the command-line string to allow for
the possibility of spaces in the paths. You can do it like this:

Dim stDBPath As String
Dim stAccessPath As String
Const Q As String = """"

stDBPath = "G:\Tma\OCIO
Shared\C-WIP2-BU\DHIMS-BU\CompletenessDB_DHIMS_2010-04-15.mdb"

stAccessPath = SysCmd(acSysCmdAccessDir) & "msaccess.exe"

Shell Q & stAccessPath & Q & " " & Q & stDBPath & Q, vbNormalFocus
 
S

Steve Stad

Thanks for the tip. The easiest way for me was to insert a hyperlink to the
db. It works fine but is there anyway to turn off the message about
....hyperlinks can be harmful .....click only hyperlinks from trusted sources.
Do you want to continue" Yes/No.

Steve
 
D

Dirk Goldgar

Steve Stad said:
Thanks for the tip. The easiest way for me was to insert a hyperlink to
the
db. It works fine but is there anyway to turn off the message about
...hyperlinks can be harmful .....click only hyperlinks from trusted
sources.
Do you want to continue" Yes/No.


Not that I know of; that's why I didn't suggest a hyperlink. However,
another alternative is to use the ShellExecute API, as described here:

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

Steve Stad

Dirk - Thanks again. I was able to use your code with a button and it worked
fine. I will have to study the 'shellexecute API' process - it sounds very
advanced.
 

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