Save As command in Access VBA

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
 
V

Van T. Dinh

Not AFAIK and unlike Excel or Word, it is not recommended an Access database
be copied while it is open.
 
T

Tim Ferguson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top