Q: Code to open a program, then close access works ok, -but..

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

Jim

I'we made this simple app in Visual Basic that copies my database to another
location (backup). 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
 
To locate another file in the same directory as the running database, I use:

dim sName as string
sname = dbengine(0)(0).name
while right$ (sname, 1) <> "\": sname = left$ (sname, len(sname)-1): wend
sname = sname & "ANOTHER_FILE.XYZ"
msgbox sname

HTH,
TC
 
Back
Top