Hello all, 
I'm having an issue with quitting/closing an external database.
Scenario:
Code is as below..
DB1 code:
DB2 Code:
Subs and Functions:

I'm having an issue with quitting/closing an external database.
Scenario:
- DB1 goes through some version checking
- DB1 is the wrong version
- DB1 calls DB2
- DB2 tries to Quit/Close DB1 <-- Fails here
- DB2 Deletes DB1
- DB2 Copies new version
- DB2 opens new version
- DB1(new version) Quits/Closes DB2
- User uses new version
Code is as below..
DB1 code:
Code:
Private Sub cmdTest_Click()
Dim anapp As Access.Application
SetEnvVar "zSSTPATHz", CurrentDb.Name
Set anapp = CreateObject("Access.Application")
anapp.OpenCurrentDatabase ("Path to DB2...")
Set anapp = Nothing
End Sub
DB2 Code:
Code:
Private Sub Form_Load()
Dim bCopy As Boolean
' check if auto copy is required
If MsgBox("About to copy new version across:" & vbCrLf & "Do you want to carry on?", vbYesNo + vbCritical, "Your version of SST is out of date") = vbNo Then
Application.Quit
End If
' get path to user sst file, close it and delete it
sDestination = GetEnvVar("Destination Path Name...")
CloseTheOpenDB (sDestination)
' wait 3 seconds for lockfile to close
doSleep 10
Kill sDestination
' state mde file name and copy new version to user sst path
sMDE = "aTest.mde"
bCopy = doCopy
' deal with copy
If bCopy = False Then
MsgBox "Copying of 'SST' file not carried out." & vbCrLf & "Please copy file manually.", _
vbCritical + vbOKOnly, "Error: Copying File"
Else
' set up environment variables for copied sst database
SetEnvVar "Destination Path Name", "copied"
SetEnvVar "Source Path Name", CurrentDb.Name
' open new instance of DB1
OpenNewSST
End If
Application.Quit
End Sub
Subs and Functions:
Code:
Option Compare Database
Sub doSleep(iSeconds As Integer)
WaitUntil = Now + TimeValue("00:00:" & iSeconds)
Do
DoEvents
Loop Until Now >= WaitUntil
End Sub
Function GetRoleName() As String
Dim spText() As String
spText() = Split(sDestination, "\")
GetRoleName = spText(5)
End Function
Sub CloseTheOpenDB(sDBPath As String)
Dim myObj As Object
Set myObj = GetObject(sDBPath)
myObj.Quit acQuitSaveNone
Set myObj = Nothing
End Sub
Function doCopy() As Boolean
Dim sTemp As String
PUID = Environ("username")
sRoot = "\\..." & PUID
sPersonal = sRoot & GetRoleName & "\"
sGroup = sRoot & "..."
sSource = sGroup & "Path details..." & sMDE
On Error GoTo EH_doCopy
FileCopy sSource, sDestination
doCopy = True
Exit Function
EH_doCopy:
' copy has failed
MsgBox "Error Num: " & Err.Number & vbCrLf & Err.Description
doCopy = False
End Function
Sub OpenNewSST()
Dim anapp As Access.Application
Set anapp = CreateObject("Access.Application")
anapp.OpenCurrentDatabase (sDestination)
Set anapp = Nothing
End Sub
Last edited: