By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,395 Members | 1,552 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,395 IT Pros & Developers. It's quick & easy.

How to copy a mdb file with VBA code

P: n/a
Dear reader,

How can I make a copy from a database which is in use.

If an mdb database is in use Access opens a small file with the extension
ldb.

This ldb file prohibits the execution of the following copy instruction:

FileCopy SourceFile, DestinationFile

The question is now, is there a possibility to make a copy of an in used mdb
file with a VBA code instruction.

Thanks for any help.

Kind regards,

Simon
Sep 30 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"Simon van Beek" <Sv********@Versatel.nlwrote in
news:48***********************@news.tele2.nl:
How can I make a copy from a database which is in use.

If an mdb database is in use Access opens a small file with the
extension ldb.

This ldb file prohibits the execution of the following copy
instruction:
Assuming Access Version >=2000

try

With CurrentProject
Shell "cmd /c copy """ & .FullName & """ """ & Replace(.FullName, .Name,
"NewName.mdb"""), vbHide
End With

The text "Shell ... vbHide" is one line of code.

--
lyle fairfield
Sep 30 '08 #2

P: n/a
On 29 Sep, 22:42, "Simon van Beek" <SvanBee...@Versatel.nlwrote:
Dear reader,

How can I make a copy from a database which is in use.

If an mdb database is in use Access opens a small file with the extension
ldb.

This ldb file prohibits the execution of the following copy instruction:

FileCopy SourceFile, DestinationFile

The question is now, is there a possibility to make a copy of an in used mdb
file with a VBA code instruction.

Thanks for any help.

Kind regards,

Simon
Try this:

Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal
lpExistingFileName _
As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long)
As Long

Sebastian C.
Sep 30 '08 #3

P: n/a
Gr********@gmail.com wrote in
news:c0**********************************@z66g2000 hsc.googlegroups.co
m:
Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal
lpExistingFileName _
As String, ByVal lpNewFileName As String, ByVal bFailIfExists As
Long) As Long
This is *terrible* advice. All it does it get you around the very
smart prohibition hardwired into Access that prevents copying of an
open file. If the file is open, you can't guarantee that the result
will not be corrupt (or in an inconsistent but noncorrupt state) no
matter what method you use to copy via the file system.

The only way to safely copy is through Jet commands. Code for that
has been posted in the Access newsgroups many, many times, and
should be easily found via searching Google Groups.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Oct 1 '08 #4

P: n/a
"David W. Fenton" <XX*******@dfenton.com.invalidwrote in
news:Xn**********************************@74.209.1 36.94:
Gr********@gmail.com wrote in
news:c0**********************************@z66g2000 hsc.googlegroups.co
m:
>Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal
lpExistingFileName _
As String, ByVal lpNewFileName As String, ByVal bFailIfExists As
Long) As Long

This is *terrible* advice. All it does it get you around the very
smart prohibition hardwired into Access that prevents copying of an
open file. If the file is open, you can't guarantee that the result
will not be corrupt (or in an inconsistent but noncorrupt state) no
matter what method you use to copy via the file system.

The only way to safely copy is through Jet commands. Code for that
has been posted in the Access newsgroups many, many times, and
should be easily found via searching Google Groups.
I can't find this, David. I tried various combinations of copy, jet, open,
file, save and replicate.

Please, post code showing how you would do it.

--
lyle fairfield
Oct 1 '08 #5

P: n/a
On 1 Oct, 05:51, "David W. Fenton" <XXXuse...@dfenton.com.invalid>
wrote:
GrafixS...@gmail.com wrote innews:c0**********************************@z66g20 00hsc.googlegroups.co
m:
Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal
lpExistingFileName _
As String, ByVal lpNewFileName As String, ByVal bFailIfExists As
Long) As Long

This is *terrible* advice. All it does it get you around the very
smart prohibition hardwired into Access that prevents copying of an
open file. If the file is open, you can't guarantee that the result
will not be corrupt (or in an inconsistent but noncorrupt state) no
matter what method you use to copy via the file system.

The only way to safely copy is through Jet commands. Code for that
has been posted in the Access newsgroups many, many times, and
should be easily found via searching Google Groups.

--
David W. Fenton * * * * * * * * *http://www.dfenton.com/
usenet at dfenton dot com * *http://www.dfenton.com/DFA/
Yes, indeed, there is no guarantee for result yet it worked for me in
the last 5 years or so and never had any corrupt file.
In our application is a subroutine for a quick backup of a backend
file (before modifying data). This function was the only solution we
found for copying an open backend file.
Of course for a successfull operation one have to be sure there is no
adding, deleting or modifing data during the copying process.

Sebastian C.
Oct 1 '08 #6

P: n/a
Gr********@gmail.com wrote in
news:0c**********************************@k30g2000 hse.googlegroups.co
m:
Yes, indeed, there is no guarantee for result yet it worked for me
in the last 5 years or so and never had any corrupt file.
In our application is a subroutine for a quick backup of a backend
file (before modifying data). This function was the only solution
we found for copying an open backend file.
Of course for a successfull operation one have to be sure there is
no adding, deleting or modifing data during the copying process.
It will work right up to the point at which it doesn't work.

I would not consider recommending such a routine to any of my
clients, since I consider it professional malpractice to gamble with
my clients' data, which is precisely what you're doing when you do
something that you are well aware can fail in some percentage of
cases.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Oct 1 '08 #7

P: n/a
"Simon van Beek" <Sv********@Versatel.nlwrote:
>How can I make a copy from a database which is in use.
Why can't you wait until the MDB is no longer in use? If things are that critical
I'd suggest using SQL Server or other database software with similar 24x7
capabilities.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
Oct 2 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.