Save As command in Access VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using Office 2003 is there a VBA equivalent in Access to Excel's "SaveCopyAs"
command, which saves a copy of the currently open file to a destination
folder, but keeps the current file active?

If so, could someone please post the VBA - or its nearest equivalent?

Thanks
 
Not AFAIK and unlike Excel or Word, it is not recommended an Access database
be copied while it is open.
 
Using Office 2003 is there a VBA equivalent in Access to Excel's
"SaveCopyAs" command, which saves a copy of the currently open file to
a destination folder, but keeps the current file active?


you could probably do something like this _completely_ untested air code:

' make a new mdb to copy into
set backupdb = CreateDatabase("g:\mybackup.mdb", etc)
backupdb.Close

' handle to currently open db
set cdb = CurrentDB()

' iterate the local tables
for each tdf in cdb.Tabledefs
' ignore the system tables; I doubt the value is
' correct but you can check that in the help files
if tdf.Attributes AND acSystemTable = 0 then
' do the copy command: look up help on the IN clause
jetSQL = "SELECT * " & _
" INTO " & tdf.Name & " IN [g:\mybackup.mdb]"
" FROM " & tdf.Name
' and carry it out
cdb.Execute jetSQL, dbFailOnError

end if
next tdf

but there might be inconsistencies if anyone is using the database at the
time. You won't get the relationships in either, but that's okay because
(a) they might be invalid and (b) they can be reconstructed if you ever
need to recover the backup.

Hope it helps


Tim F
 
Back
Top