Open another app then close Access (from within Access) -problem

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

I'we made this simple app in Visual Basic 6 that copies my database to
another
location (as a backup-app). I have a commandbutton on my main (Access) form
with the
code below. However, if I run the copy utility on it's own then it works ok,
i.e. the database gets copied (backuped) to another place. But when I run it
from this button then I get "Run-Time Error "53": File not found. Is Access
somehow still up and running or what am I doing wrong?
Secondly, the database and the backup utility will always be in the same
directory. Is there a way to get the path to the backup app instead of like
in the code below (which will not find the app if for example the database
directory is moved to another location)? Jim.

Private Sub cmd_open_backup_Click()
Dim RetVal

If MsgBox("Are you sure you want to quit?", vbYesNo) = vbYes Then

RetVal = Shell("C:\Documents and Settings\MyComputer\Desktop\backup.exe",
vbNormalFocus)
Application.Quit

End If

End Sub
 
Thank you Arvin for your response.

First question:
The code behind the "Backup-button" (on the visual basic 6 backup app) is
simply:

Private Sub cmd_kopiera_Click()
Dim messagebox As String
FileCopy "Testdb.mdb", "Testdb_backup.mdb"
messagebox = MsgBox("Backup Ok", vbInformation, "Backup Ok")
End Sub

The task manager tells me that no instance of Access would be running, still
the backup app wont work when launched from within Access. I also tried to
change the code to quit Access to "Docmd.Quit" as you proposed, but the
result is exactly the same. Second question I'll look into later. Thanx,
Jim.
 
It's not the VB app that's keeping the instance of Access open. When you
call the VB app from an Access app, you are calling it from an open instance
of Access. It is that instance that you need to close with: DoCmd.Close.

Have a look at this code snippet from a versioning app I've written in
Access. It checks for a new version then downloads it if it exists, then
opens the new app, while closing itself:

FileCopy strServPath, strCurPath ' this is the copying

DoEvents ' let it get done

Call fHandleFile(strCurPath, WIN_NORMAL) ' this opens the new file

Exit_Here:
DoCmd.Quit ' this exits the current app
Exit Sub

FileCopy is a VBA command and fHandleFile was written by Dev Ashish and is
available:

http://www.mvps.org/access/api/api0018.htm
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
Thanks Arvin for your response. I looked into it and fiddled with it but
still couldn't get it right. Then I started fiddling with the visual basic
code (backup.exe) and finally I got it working. The problem was that I had
not the path "explained" right to the app on where to find this database to
be copied.
Despite of that the database always was in the same directory that
backup.exe, for backup.exe to find it when opened from the database itself
the path had to be "App.Path & "\" & "db.."

Thanks again, Jim.
 
Back
Top