Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying Current Database

Status
Not open for further replies.

Aqif

Programmer
Apr 27, 2002
240
0
0
AU
Hi:)

I am using Access 97 and I am trying to make a copy of my database which is opened by the user. I am uaing follwing syntax

Dim SrcFile, DestFile as String

SrcFile = CurrDB.Name
DestFile = "C:\BackDatabase.mdb"

MsgBox SrcFile & vbCrLf & DestFile

FileCopy SrcFile, DestFile


For some reason it is not working for the current database maybe because its opened and locked. When I try to copy another file it gives no problem.

Any syggestions?

Cheers!
ÙÇãá
 
Hi
Have tried this before and had the same problems. The only way around I could find was to close database and run the copy as a scheduled task.
My database was only used during office hours so ran the backup copy overnight!!
If this option is viable for you I will post the code that I used.

Alan
 
Hi :)

Thanks for your reply. I can even tell the user to manually copy the file. But I liked to copy the file from code itself. Maybe i will create a new database and export all objects.

Cheers!
ÙÇãá
 
Aqif

Also please see this earlier thread
thread 705-182150
 
aqif
Not sure if you solved your prob, but came up with this bad boy of a batch file which works a treat for me. see what you think. Run batch file from scheduler and don't forget to alter paths, etc

@echo off

rem Batch file to backup Live GTS FEP Database suite
rem File in Source directory - see below
rem Created 26/09/02 by DT

rem *******************************************************************************

rem *** DECLARATIONS ***

Title Portfolio Support Database Backup

rem PATHWAYS
rem Source Pathway so that it can run on any NTS box
set source=\\IHCN01\PFSUP\DATABASErem Online Backup Pathway so that it can run on any NTS box
set backup=\\IHCN01\PFSUP\BACKUP
rem Secure Backup:eek:nline, but non-public access - temporary
set secure=\\CDTE01\MCFADDEA\DATABASE\SECURE


rem FILES
rem GTS Extract Database
set extract="%source%GTS TRADE EXTRACT.MDB"
rem Compliance Analysis Database
set compliance="%source%GAS COMPLIANCE ANALYSIS.MDB"
rem Settlement Export
set settlements="%source%GAS SETTLEMENTS EXPORT.MDB"
rem Confirmations
set confirm="%source%CONFIRMATIONS.MDB"
rem Secure Workgroup File
set workgroup="%source%LOCAL.MDW"


rem *******************************************************************************

rem *** INITIALISE ***

rem Set current date into %datestamp%
%source%setdate.exe
call dateset

rem Open Log COPYLOG.LOG in %source%
set log=%source%pscopylog.log
echo Portfolio Support Database Backup Log for %datestamp% > %log%
echo. >> %log%

rem *******************************************************************************

rem *** MAIN ***

echo Saving Database Files to Backup
echo Saving Database Files to Backup >> %log%

rem Report to Log if expected Source files are not found when saving to Backup area

if not exist %extract% echo !!! WARNING - %extract% file not found !!! >> %log%
if exist %extract% call backupPSFile.bat %extract% %backup% Backup
if not exist %compliance% echo !!! WARNING - %compliance% file not found !!! >> %log%
if exist %compliance% call backupPSFile.bat %compliance% %backup% Backup
if exist %settlement% call backupPSFile.bat %settlements% %backup% Backup
if exist %confirm% call backupPSFile.bat %confirm% %backup% Backup
if not exist %workgroup% echo !!! WARNING - %workgroup% file not found !!! >> %log%
if exist %workgroup% call backupPSFile.bat %workgroup% %backup% Backup

echo Saving Database Files to Secure Area
echo. >> %log%
echo Saving Database Files to Secure Area >> %log%

if exist %extract% call backupPSFile.bat %extract% %secure% Secure
if exist %compliance% call backupPSFile.bat %compliance% %secure% Secure
if exist %settlement% call backupPSFile.bat %settlements% %secure% Secure
if exist %confirm% call backupPSFile.bat %confirm% %secure% Secure
if exist %workgroup% call backupPSFile.bat %workgroup% %secure% Secure

echo. >> %log%
echo Backup Complete >> %log%

rem *******************************************************************************

rem *** CLOSE ***
:end
echo.
rem Print Report
echo Printing Log ...
net use lpt1: \\ghcn05\ghclz95
type %log% > lpt1:
net use lpt1: /d
wait 2

rem eop
 
See Microsoft Knowledge Base Article - 207703
or cut/copy the following link. I used it and it works pretty good. I added some code to make it more versatile. Make sure you head the warning in the article: If while copying, the file changes, it could corrupt the copied file (destination). I haven't had a problem, but haven't tested it in the database's network environment.

Note: I used method 1. Did not test method 2.


Myk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top