Open,Run&Close another database

J

John

I have a database that runs and once it gets done running I want to have it
open database2, run and then close database2. So far I got it to open
database2 but I can't figure out how to run then close database2. Any help
would be greatly appreciated, Thanks.
 
K

Klatuu

What do you mean by "run database2"?
If you open it, then you have visibility to it's objects and can use them.
If what you are trying to do is launch it as a separate application, then you
need to use the Shell function.
 
L

LambertH

Here's one way.

Sub sOpenDataBase(strDbName As String)
Dim ProcID As Long
Dim strCommandLine As String
' Dim sDataPath As String

If Not FileExists(strDbName) Then
MsgBox "Cannot fine the file " & strDbName & "@Please contact the
database administrator@@"
Else
strCommandLine = Quote(SysCmd(acSysCmdAccessDir) & _
"MSACCESS.EXE") & " " & Quote(strDbName)
ProcID = CLng(Shell(strCommandLine, vbNormalFocus))
Application.Quit acQuitSaveNone ' quit this Db
End If
End Sub

The essential thing is that you launch the other application (using Shell)
and then when shell returns control you simply quit the current application.

Here's the code for FileExists()

Function FileExists(strFile As String) As Boolean
' Comments : Determines if the file exists
' Works for hidden files and folders
' Parameters: strFile - file to check
' Returns : True if the file exists, otherwise false
Dim intAttr As Integer

On Error Resume Next
'GET THE FILE ATTRIBUTE INSTEAD OF THE LENGTH OF THE FILE NAME
intAttr = GetAttr(strFile)
FileExists = (Err = 0)
End Function
 

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